【发布时间】:2011-01-28 03:37:21
【问题描述】:
我想将 IVApplication 的接口引用从 Visio 加载项发送到我的另一台 COM 服务器。但我有 Ole 例外。现在我这样做了:
Visio 加载项中的代码:
var
IStrm: IStream;
hres: HResult;
rhglobal: HGLOBAL;
VisioAppl: IVApplication;
begin
hres := CreateStreamOnHGlobal(0, TRUE, IStrm);
if Succeeded(hres) then
hres := CoMarshalInterface(IStrm, IID_IVApplication, VisioAppl,
MSHCTX_LOCAL, 0,
MSHLFLAGS_NORMAL);
if (Succeeded(hres)) then
begin
hres := GetHGlobalFromStream(IStrm, rhglobal);
if Succeeded(hres) then
Result := rhglobal;
IStrm := nil;
end;
end;
之后,我创建了我的 COM 服务器实例并将 rhglobal 传递给他。
我的 COM 服务器代码:
procedure (AHGlobal: HGlobal);
var
VisioAppl: Visio_TLB.IVApplication;
iStrm: IStream;
hres: HResult;
begin
iStrm := Nil;
VisioAppl:= nil;
hres := CreateStreamOnHGlobal(AHGlobal, FALSE, iStrm);
if (SUCCEEDED(hres)) then
begin
hres := CoUnmarshalInterface(iStrm, Visio_TLB.IVApplication, VisioAppl);
iStrm := nil;
ShowMessage('Result:' + BoolToStr(SUCCEEDED(hres))); <-- result 0
ShowMessage(VisioAppl.ProductName); <---- Error
end;
end;
【问题讨论】:
-
欢迎来到 Stack Overflow。你在问什么“结果为0”?如果你在谈论“hres”,它在你的两个代码示例中被分配了 5 次。你问的是哪一个?如果你真的问了一个问题,你就有更好的机会得到答案。
-
我认为这是显而易见的。在代码中放置不良结果已用注释“
-
如何实际计算在这种情况下设置的 hres 并推动它通过一些东西来计算错误代码,只是有时他们实际上会告诉你你是如何搞砸的 :) 我个人的猜测是可能您的特定 visio 界面没有代理。
标签: delphi com interface marshalling ole