VC创建的COM组件事件的out参数,在delphi里怎样进行赋值返回? ( 积分: 200 )

  • 主题发起人 主题发起人 microkong
  • 开始时间 开始时间
M

microkong

Unregistered / Unconfirmed
GUEST, unregistred user!
VC生成的idl定义:
[id(1), helpstring("method DoSome")] HRESULT DoSome([out]LPSTR returnvalue, [out]int* returncode);

VC的CProxy_IServEvents类(用ATL生成)里定义:
HRESULT CProxy_IServEvents::Fire_DoSome(LPSTR returnvalue, INT * returncode)
{
....
//参数定义:
pvars[1].vt = VT_BYREF | VT_LPSTR;
pvars[1].pcVal = returnvalue;
pvars[0].vt = VT_BYREF | VT_INT;
pvars[0].pintVal = returncode;
....
}

用VC赋值没有问题:
void __stdcall CEventSink::DoSome(LPSTR returnvalue, INT * returncode)
{
strcpy(returnvalue, "123");
*returncode = 1;
}

但在delphi里赋值就不行

TLB里的定义:
TServDoSome = procedure(Sender: TObject;
var returnvalue: {??PChar}OleVariant;
var returncode: OleVariant) of object;

procedure TServ.InvokeEvent(DispID: TDispID; var Params: TVariantArray);
begin
case DispID of
-1: Exit; // DISPID_UNKNOWN
1: if Assigned(FOnDoSome) then
FOnDoSome(Self, Params[0] {out SYSINT}, Params[1] { ??PChar OleVariant});
end; {case DispID}
end;

自己程序里事件的赋值操作:
procedure TForm1.Serv1DoSome(Sender: TObject; var returnvalue, returncode: OleVariant);
begin
returncode := 1;
returnvalue := '123';
end;
COM组件里的值没有改变。
 
VC生成的idl定义:
[id(1), helpstring("method DoSome")] HRESULT DoSome([out]LPSTR returnvalue, [out]int* returncode);

VC的CProxy_IServEvents类(用ATL生成)里定义:
HRESULT CProxy_IServEvents::Fire_DoSome(LPSTR returnvalue, INT * returncode)
{
....
//参数定义:
pvars[1].vt = VT_BYREF | VT_LPSTR;
pvars[1].pcVal = returnvalue;
pvars[0].vt = VT_BYREF | VT_INT;
pvars[0].pintVal = returncode;
....
}

用VC赋值没有问题:
void __stdcall CEventSink::DoSome(LPSTR returnvalue, INT * returncode)
{
strcpy(returnvalue, "123");
*returncode = 1;
}

但在delphi里赋值就不行

TLB里的定义:
TServDoSome = procedure(Sender: TObject;
var returnvalue: {??PChar}OleVariant;
var returncode: OleVariant) of object;

procedure TServ.InvokeEvent(DispID: TDispID; var Params: TVariantArray);
begin
case DispID of
-1: Exit; // DISPID_UNKNOWN
1: if Assigned(FOnDoSome) then
FOnDoSome(Self, Params[0] {out SYSINT}, Params[1] { ??PChar OleVariant});
end; {case DispID}
end;

自己程序里事件的赋值操作:
procedure TForm1.Serv1DoSome(Sender: TObject; var returnvalue, returncode: OleVariant);
begin
returncode := 1;
returnvalue := '123';
end;
COM组件里的值没有改变。
 
问题主要出在 LPSTR ,

..............
 
后退
顶部