如何使用 PSafeArray 从 delphi 调用带有数组的 .NET COM 方法?

发布于 2024-09-02 04:00:30 字数 1609 浏览 9 评论 0原文

我有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-09-09 04:00:30

我从未尝试过您需要的内容,但快速搜索发现了以下文章:

I have never tried what you need but a quick search found the following articles:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文