Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将SAFEARRAY从C#传递到COM?_C#_Com - Fatal编程技术网

如何将SAFEARRAY从C#传递到COM?

如何将SAFEARRAY从C#传递到COM?,c#,com,C#,Com,我有一个ATLCOM服务器,接口的方法是 CVivsBasic::UpdateSwitchPlan(BSTR plan_name, SAFEARRAY* plan) 此函数的IDL如下所示 typedef struct { LONG time_to_play; BSTR ecportid; } SwitchPlanItem; HRESULT UpdateSwitchPlan([in] BSTR plan_name, [in] SAFEARRAY(SwitchPlanI

我有一个ATLCOM服务器,接口的方法是

CVivsBasic::UpdateSwitchPlan(BSTR plan_name, SAFEARRAY* plan)
此函数的IDL如下所示

typedef struct  
{   
    LONG time_to_play;
    BSTR ecportid;
} SwitchPlanItem;
HRESULT UpdateSwitchPlan([in] BSTR plan_name, [in] SAFEARRAY(SwitchPlanItem) plan) ;    
我试着这样称呼它:

        internal void UpdateSwitch(string plan_name, string ecportid)
    {
        SwitchPlanItem sp1;
        sp1.time_to_play = 33;
        sp1.ecportid = ecportid;

        SwitchPlanItem sp2;
        sp2.time_to_play = 33;
        sp2.ecportid = ecportid;

        SwitchPlanItem[] sps = { sp1, sp2 };

        sdk.UpdateSwitchPlan(plan_name, sps);
    }

但它崩溃了。将SAFEARRAY从C#传递到COM的正确方法是什么?

我认为这里的问题是,您使用的是用户定义类型(UDT)的
SAFEARRAY
VARIANT
BSTR
IUnknown
SAFEARRAY
,但对于
UDT
,您需要帮助封送员。请参阅MSDN中关于的这篇文章。

我认为这个问题的答案与此类似:


基本上,使用传入SAFEARRAY(STRUCT)的接口的C#客户端必须在导入的COM服务器引用属性上定义嵌入互操作类型=False

我也有同样的问题。有办法做到这一点吗?文章从本地客户端的角度提到了一些东西。。。