我有一个用这个 IDL 代码定义的 COM 库:
struct T_GPSParamsMap
{
BSTR Key;
BSTR Value;
}T_GPSParamsMap;
struct T_FwClient
{
BSTR Alias;
SMSFilterActionEnum Action;
BSTR Text;
int ToCall;
int ToState;
SAFEARRAY(T_GPSParamsMap) GpsData;
} T_FwClient;
struct T_SMSAction
{
int ActionID;
SMSFilterActionEnum Action;
BSTR Text;
BSTR Folder;
BSTR DestAddress;
int ToCall;
int ToState;
SAFEARRAY(T_GPSParamsMap) GpsData;
VARIANT_BOOL forwardToNotListed;
SAFEARRAY(T_FwClient) FwClients;
} T_SMSAction;
[
object,
uuid(F7942BCA-5122-46BB-94DB-89F5071842E4),
dual,
oleautomation,
nonextensible,
helpstring("ISMSFilter Interface"),
pointer_default(unique)
]
interface ISMSFilterWrapper : IDispatch{
[id(1), helpstring("method GetFilterResult")]
HRESULT Init([in] BSTR schema_file_path, [out, retval] long* pVal);
[id(2), helpstring("method GetFilterResult")]
HRESULT ApplyFilter([in] T_SMS* sms, [out, retval] long* pVal);
[id(3), helpstring("method GetFilterResult")]
HRESULT GetFilterResult([in, out] T_SMSAction* ret_val, [out, retval] long* pVal);
};
现在,我以这种方式在 c# 中使用它:
SMSFilterLib.T_SMS smsFilter = new SMSFilterLib.T_SMS();
SMSFilterLib.T_SMSAction smsRule = new SMSFilterLib.T_SMSAction();
smsFilter.CalledParty = Convert.ToString(RadioID);
smsFilter.CallingParty = "1";
smsFilter.Text = Text;
m_smsFilter.ApplyFilter(ref smsFilter);
int RV = m_smsFilter.GetFilterResult(ref smsRule);
最后一行引发异常(从意大利语翻译):
HResult = -2146233054
“System.TypeLoadException”类型的第一次机会异常无法编组“SMSFilterLib.T_SMSAction”类型的归档 GpsData:不支持此类型的编组。
这个 COM 库用于旧的 VB6 应用程序并且运行良好..
我已经使用 Visual Studio 的标准 CCW 将它导入到 c# 中(通过引用添加它),但它可能需要自定义 CCW。
有人可以给我一些建议如何使用它吗?
问候,丹尼尔