Hallo zusammen,
ich habe ein Problem in einem ActiveX Projekt:
Ich erzeuge in einem "Thread 1" COM-Objekte und möchte diese in N anderen Threads verwenden. Die Marshaling Unit ist in Thread1 und Thread2 eingebunden.
In das Marshaling Cookie "MCClientLogin1" wird in "Thread1" einen korrekten Wert geschrieben.
Das von mir verwendete Marshaling scheint nicht zu funktionieren, laut Debugger ist ClientLogin1 in "Thread 2" auch nach ausführen von "GIT.GetInterfaceFromGlobal" NIL.
Somit kann ich nicht aus Thread 2 auf mein COM-Objekt zugreifen.
Kennt jemand eine Lösung bzw. einen Workaround?
Vielen Dank!
Thread 1
Delphi-Quelltext
1:
| GIT.RegisterInterfaceInGlobal(ClientLogin1,IClientlogin,MCClientLogin1); |
Thread 2
Delphi-Quelltext
1:
| GIT.GetInterfaceFromGlobal (MCClientLogin1, IClientLogin, ClientLogin1); |
Marshaling Unit
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
| unit UMarshaling;
interface
uses ActiveX, Windows;
const CLSID_StdGlobalInterfaceTable : TGUID = '{00000323-0000-0000-C000-000000000046}';
type IGlobalInterfaceTable = interface(IUnknown) ['{00000146-0000-0000-C000-000000000046}'] function RegisterInterfaceInGlobal(pUnk: IUnknown; const riid: TIID; out dwCookie: DWord): HResult; stdcall; procedure RevokeInterfaceFromGlobal( dwCookie: DWord); safecall; function GetInterfaceFromGlobal(dwCookie: DWord; const riid: TIID; out ppv): HResult; stdcall; end;
function GIT: IGlobalInterfaceTable;
implementation
uses ComObj;
function GIT: IGlobalInterfaceTable; var GITIntf: IGlobalInterfaceTable; begin if not Assigned(GITIntf) then GITIntf := CreateComObject(CLSID_StdGlobalInterfaceTable) as IGlobalInterfaceTable; Result := GITIntf end; |