我有一个 ATL COM 服务器,其中接口的方法是
CVivsBasic::UpdateSwitchPlan(BSTR plan_name, SAFEARRAY* plan)
Run Code Online (Sandbox Code Playgroud)
这个函数的 IDL 看起来像
typedef struct
{
LONG time_to_play;
BSTR ecportid;
} SwitchPlanItem;
HRESULT UpdateSwitchPlan([in] BSTR plan_name, [in] SAFEARRAY(SwitchPlanItem) plan) ;
Run Code Online (Sandbox Code Playgroud)
我尝试从 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);
}
Run Code Online (Sandbox Code Playgroud)
但它崩溃了。将 SAFEARRAY 从 C# 传递到 COM 的正确方法是什么?