【发布时间】:2009-09-15 04:23:46
【问题描述】:
我有一个ATL COM Server,接口的方法是
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);
}
但它崩溃了。将 SAFEARRAY 从 C# 传递到 COM 的正确方法是什么?
【问题讨论】: