to JamesBond_L,确实可能可以运行
具体为什么要这样,得去看一下Com+中ObjectContext的机制
李维在他的com+书中,为了能统一使用coXXX.create,他修改了
ComObj.pas中相应的实现:
function CreateComObject(const ClassID: TGUID): IUnknown;
begin
//!!! Modified By Gordon Li
if (Getobjectcontext=nil)then
OleCheck(CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or
CLSCTX_LOCAL_SERVER, IUnknown, Result))//old
else
GetObjectContext.CreateInstance(ClassID,IUnknown,Result);
end;
function CreateRemoteComObject(const MachineName: WideString;
const ClassID: TGUID): IUnknown;
const
LocalFlags = CLSCTX_LOCAL_SERVER or CLSCTX_REMOTE_SERVER or CLSCTX_INPROC_SERVER;
RemoteFlags = CLSCTX_REMOTE_SERVER;
var
MQI: TMultiQI;
ServerInfo: TCoServerInfo;
IID_IUnknown: TGuid;
Flags, Size: DWORD;
LocalMachine: array [0..MAX_COMPUTERNAME_LENGTH] of char;
begin
//Modifried Bygordon Li
if (GetObjectContext=nil) then
begin
if @CoCreateInstanceEx = nil then
raise Exception.CreateRes(@SDCOMNotInstalled);
FillChar(ServerInfo, sizeof(ServerInfo), 0);
ServerInfo.pwszName := PWideChar(MachineName);
IID_IUnknown := IUnknown;
MQI.IID := @IID_IUnknown;
MQI.itf := nil;
MQI.hr := 0;
{ If a MachineName is specified check to see if it the local machine.
If it isn't,do
not allow LocalServers to be used. }
if Length(MachineName) > 0 then
begin
Size := Sizeof(LocalMachine);
// Win95 is hypersensitive to size
if GetComputerName(LocalMachine, Size) and
(AnsiCompareText(LocalMachine, MachineName) = 0) then
Flags := LocalFlags else
Flags := RemoteFlags;
end else
Flags := LocalFlags;
OleCheck(CoCreateInstanceEx(ClassID, nil, Flags, @ServerInfo, 1, @MQI));
OleCheck(MQI.HR);
Result := MQI.itf;
end
else
GetObjectContext.CreateInstance(ClassID,IUnknown,Result);
end;
如果你按上法修改,就可以放心调用coXXX.create