When writing COM components in Delphi5, you will not get the objectContext to return to getObjectContext to return NIL. This makes things handling can't complete correctly. Someone tells me to add a MTXEx.dll statement before the COM component. It does solve this Question, but it seems that it is not stable .procedure TGENTITYOBJ.INITIALIZE; Begin Inherited; loadLibrary ('mtxex.dll'); END; but I can get ObjectContext in Delphi6, I can get ObjectContext. I saw D6 The MTX unit and D5 are different, and this will not blame the Win2000 (COM ) yet, so the MTX unit is still loaded in the MTX unit in the MTX unit in the MTX unit in D5.
253 lines in the D5 MTX unit. IMPLEMEMentation
Uses comobj;
type TGetObjectContextProc = function (var ObjectContext: IObjectContext): HRESULT; cdecl; TSafeRefProc = function (const rid: TGUID; Unk: IUnknown): Pointer; cdecl; var GetObjectContextProc: TGetObjectContextProc = nil; SafeRefProc: TSafeRefProc = nil; MtsProcsLoaded: Boolean = False;
procedure LoadMtsProcs; var Mtxdll: HModule; begin if MtsProcsLoaded then Exit; MtsProcsLoaded: = True; Mtxdll: = GetModuleHandle ( 'mtxex.dll'); if mtxdll <> 0 then begin @GetObjectContextProc: = GetProcAddress (Mtxdll, 'GetObjectContext') @Saferefproc: = getProcaddress (Mtxdll, 'Saferef'); end; end;
Function getObjectContext: IOBJECTCONTEXT; Begin LoadMtsProcs; if Assigned (getObjectContextProc (Result) ELSE Result: = nil; // Empty when handling.
The MTX unit in D6 is different.
IMPLEMENTATION
Uses comobj;
type TGetObjectContextProc = function (var ObjectContext: IObjectContext): HRESULT; cdecl; /// TCoGetObjectContextProc = function (const riid: TGUID; var ObjectContext: IObjectContext): HRESULT; stdcall; TSafeRefProc = function (const rid: TGUID; Unk: IUnknown) : Pointer; cdecl; var GetObjectContextProc: TGetObjectContextProc = nil; CoGetObjectContextProc: TCoGetObjectContextProc = nil; /// SafeRefProc: TSafeRefProc = nil; MtsProcsLoaded: Boolean = False; function IsComPlusPlatform: boolean; // whether the COM var Ver: TOsVersionInfo; begin Ver.dwosveionInfiSize: = sizeof (Ver); getversionEx (Ver); if (Ver.dwplatformID = Ver_Platform_WIN32_NT) and /// (Ver.dwmajorversion> = 5) THEN Result: = true // else result: = false; //
procedure LoadMtsProcs; var Mtxdll: HModule; begin if MtsProcsLoaded then Exit; MtsProcsLoaded: = True; if IsComPlusPlatform then begin Mtxdll: = GetModuleHandle ( 'ole32.dll'); /// if mtxdll <> 0 then /// @CoGetObjectContextProc: = GetProcAddress (Mtxdll, 'CoGetObjectContext'); end /// else begin Mtxdll: = GetModuleHandle ( 'mtxex.dll'); if mtxdll <> 0 then begin @GetObjectContextProc: = GetProcAddress (Mtxdll, 'GetObjectContext'); @SafeRefProc : = GetProcAddress (Mtxdll, 'SafeRef'); end; end; end; function GetObjectContext: IObjectContext; const IID_IObjectContext: TGUID = '{51372AE0-CAE7-11CF-BE81-00AA00A2FA25}'; /// begin LoadMtsProcs; if Assigned ( CoGetObjectContextProc) then /// CoGetObjectContextProc (IID_IObjectContext, Result) /// else if Assigned (GetObjectContextProc) then OleCheck (GetObjectContextProc (Result)) else Result: = nil; end; diagonal thin multi-part you just need these unit The MTX plus D5 is OK. Then save the current directory compiler of your program to get ObjectContext.