如何使用 PSafeArray 从 delphi 调用带有数组的 .NET COM 方法?
我有一个 .NET (4.0) 接口,它是使用 ServicedComponent
COM+ 类实现的:
interface DotNetIface
{
void MethodRef(var System.Guid guid);
void MethodArray(System.Guid[] guids, params object[] parameters);
void MethodCStyle([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct, SizeConst=5)]System.Guid[] guids);
}
现在我使用 Delphi 2007 导入向导来导入类型库,并且符合预期 我得到以下签名:
procedure MethodRef(var guid : TGuid);
procedure MethodArray(guids : PSafeArray);
procedure MethodCStyle(var guids : ClrGuid /* from mscorlib_TLB */);
如果我现在像这样调用“ref”方法,它工作正常:
procedure CallByRef(guid : TGuid);
var
test : TGuid;
begin
test := ...
comRef.MethodRef(guid);
end;
现在我还需要数组方法
procedure CallArray();
var
localGuid : TGuid;
arrayVariant : OleVariant;
begin
arrayVariant := VarArrayCreate([0,4], varVariant /* dont know here */);
arrayVariant[0] := localGuid; /* compile error, cannot cast implicitly */
comRef.MethodArray(PSafeArray(TVarData(arrayVariant.VArray)), /* here this object... PSafeArray works actually*/);
end;
现在最后我尝试使用 ac 数组,
procedure CallCStyle();
var
localGuid : TGuid;
arrayOfGuid : array [0..4] of ClrGuid;
begin
arrayOfGuid[0] := ClrGuid(localGuid);
comRef.MethodCStyle(PSafeArray(/* now i dont know put it*/, /* here this object... PSafeArray works actually*/);
end;
我真的不知道如何使这个工作。 我希望有人对 COM 编组有更多经验 谢谢
侧面节点:
我找到了 VT_CLSID,我认为它可以传递给 SafeArrayCreate,但我不知道如何起诉
I have an .NET (4.0) interface which is implemented with a ServicedComponent
COM+ class:
interface DotNetIface
{
void MethodRef(var System.Guid guid);
void MethodArray(System.Guid[] guids, params object[] parameters);
void MethodCStyle([MarshalAs(UnmanagedType.LPArray, ArraySubType=UnmanagedType.Struct, SizeConst=5)]System.Guid[] guids);
}
Now I used the Delphi 2007 import wizard to import the type library, and as expected
I get the following signatures:
procedure MethodRef(var guid : TGuid);
procedure MethodArray(guids : PSafeArray);
procedure MethodCStyle(var guids : ClrGuid /* from mscorlib_TLB */);
If i now call the "ref" method like this it works fine:
procedure CallByRef(guid : TGuid);
var
test : TGuid;
begin
test := ...
comRef.MethodRef(guid);
end;
Now I also need the array method
procedure CallArray();
var
localGuid : TGuid;
arrayVariant : OleVariant;
begin
arrayVariant := VarArrayCreate([0,4], varVariant /* dont know here */);
arrayVariant[0] := localGuid; /* compile error, cannot cast implicitly */
comRef.MethodArray(PSafeArray(TVarData(arrayVariant.VArray)), /* here this object... PSafeArray works actually*/);
end;
Now lastly i tried with a c array
procedure CallCStyle();
var
localGuid : TGuid;
arrayOfGuid : array [0..4] of ClrGuid;
begin
arrayOfGuid[0] := ClrGuid(localGuid);
comRef.MethodCStyle(PSafeArray(/* now i dont know put it*/, /* here this object... PSafeArray works actually*/);
end;
I seriously dont know how to make this work.
I hope someone has more experience with COM marshalling
thx
Side node:
I found VT_CLSID which i think can be passed for SafeArrayCreate, but I am not sure how to sue that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未尝试过您需要的内容,但快速搜索发现了以下文章:
I have never tried what you need but a quick search found the following articles: