thanks for the helpful references walter. ok, i've passed the olecheck
and nothing go wrong. but still after i marshal and unmarshal the
interface i get the 'Invalid variant operation' each time i try to
access the interface method.
here is my complete code.
//--------------------- interface ------------------------//
const
LIBID_Server: TGUID = '{EB70845E-9DC2-42F2-87FC-AFFD45B4AE78}';
IID_IServer: TGUID = '{D86B9849-2A17-4F75-9951-64B8A8FE0DE0}';
CLASS_Server: TGUID = '{645ECCBB-03CC-46D1-8E87-113BFCF7ADBE}';
IID_IClient: TGUID = '{CD8A95A5-9099-4813-AD07-61CE4ABB26C1}';
IClient = interface(IDispatch)
['{CD8A95A5-9099-4813-AD07-61CE4ABB26C1}']
procedure Something(const Params: WideString); safecall;
end;
//--------------------- client --------------------------//
Tclientclass = class (TAutoIntfObject, IClient)
public
constructor Create; reintroduce;
procedure Something(const Params: WideString); safecall;
end;
constructor Tclientclass.Create;
var
resultLib: ITypeLib;
begin
OleCheck(LoadRegTypeLib(LIBID_Server, 1, 0,0, resultLib ));
inherited Create(resultLib, IID_IClient);
end;
procedure Tclientclass.Something(const Params: WideString);
begin
end;
var clientclass: Tclientclass;
procedure TMainClient.connect;
public
clientclass := Tclientclass.create;
IServer.registerclient(clientclass as IDispatch);
end;
//------------------ server ----------------------------//
var
clientclass: OleVariant;
FStream: Pointer;
procedure servermain.registerclient(x: OleVariant)
begin
clientclass := x;
OleCheck(CoMarshalInterThreadInterfaceInStream (IDispatch,
clientclass, IStream (FStream)));
end;
procedure servermain.dosomething;
begin
clientclass.Something(Params); // runs ok
end;
procedure serverotherthread.dosomething;
begin
OleCheck(CoGetInterfaceAndReleaseStream (IStream (FStream),
IDispatch, clientclass));
clientclass.Something(Params); //error - 'invalid variant operation'
end;
i guess its something with the olevariant or idispatch thing. i've
tried to pass the clientclass as IClient and it didn't even pass the
olecheck.