我有一个ATL COM服务器,该接口的方法是
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) ;
我试图从C#这样称呼它:
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);
}
但它崩溃。 什么是从C#中的SAFEARRAY传递给COM正确的方法是什么?