Delphi5在Win2000下创建基于Com+的组建需要对Delphi源代码进行如下修改: 在Mtx单元,添加:TCoGetObjectContextProc = function(const riid: TGUID; var ObjectContext: IObjectContext): HRESULT; stdcall; CoGetObjectContextProc: TCoGetObjectContextProc = nil;然后将以下过程更改为: //其实就是吧Delphi6下面相关的过程移植到Delphi5下即可 function IsComPlusPlatform: boolean; var Ver: TOsVersionInfo; begin Ver.dwOSVersionInfoSize := sizeof(Ver); GetVersionEx(Ver); if (Ver.dwPlatformID = VER_PLATFORM_WIN32_NT) and (Ver.dwMajorVersion >= 5) then Result := true else Result := false; end;
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;
是在执行mtxex.dll 中的GetObjectContent过程时出错的!btw, LoadLibrary 和 GetModuleHandle 除了在计数器上有区别外,还有没有其他的区别,为什么有时候用GetModuleHandle可以,有时候又必须用LoadLibrary?
在Mtx单元,添加:TCoGetObjectContextProc = function(const riid: TGUID; var ObjectContext: IObjectContext): HRESULT; stdcall; CoGetObjectContextProc: TCoGetObjectContextProc = nil;然后将以下过程更改为: //其实就是吧Delphi6下面相关的过程移植到Delphi5下即可
function IsComPlusPlatform: boolean;
var
Ver: TOsVersionInfo;
begin
Ver.dwOSVersionInfoSize := sizeof(Ver);
GetVersionEx(Ver);
if (Ver.dwPlatformID = VER_PLATFORM_WIN32_NT) and
(Ver.dwMajorVersion >= 5) then
Result := true
else Result := false;
end;
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;