如何使用PSafeArray从delphi调用带有数组的.NET COM方法? [英] How to call a .NET COM method with an array from delphi using PSafeArray?

查看:145
本文介绍了如何使用PSafeArray从delphi调用带有数组的.NET COM方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET(4.0)接口,该接口是通过ServicedComponent COM +类实现的:

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);
}

现在,我使用了Delphi 2007导入向导来导入类型库,并且符合预期 我得到以下签名:

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 */);

如果我现在这样调用"ref"方法,它将很好:

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;

现在我还需要数组方法

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;

现在我终于尝试了一个c数组

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;

我真的不知道该怎么做. 我希望有人在COM编组方面有更多经验

I seriously dont know how to make this work. I hope someone has more experience with COM marshalling thx

侧面节点:

我找到了我认为可以为SafeArrayCreate传递的VT_CLSID,但我不确定该如何起诉

I found VT_CLSID which i think can be passed for SafeArrayCreate, but I am not sure how to sue that

推荐答案

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

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

  • Scripting Your Delphi Applications (Shows a Good example of converting a variant array to PSafeArray
  • How to do a SafeArray Access with a DLL for Variants (OLE)
  • The mysteries of PSafeArray

这篇关于如何使用PSafeArray从delphi调用带有数组的.NET COM方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆