【发布时间】:2012-05-25 10:37:24
【问题描述】:
我有一个带有 IDL 文件的 COM 接口,其中声明了以下内容:
typedef [uuid(D7B6C495-FFF3-11E0-8A39-08002700D831)]
struct PORT_CONFIG
{
unsigned char rack;
unsigned short port;
unsigned char offset;
} PORT_CONFIG;
[object, uuid(D7B6C492-FFF3-11E0-8A39-08002700D831), dual, nonextensible, pointer_default(unique)]
interface IMED704 : IDispatch
{
[id(5), helpstring("method PortConfig")] HRESULT PortConfig([in] SAFEARRAY(PORT_CONFIG) portCfg, [in, defaultvalue(-1)] VARIANT_BOOL clearInputs);
};
现在在我的 C# 程序中,我尝试调用 PortConfig 方法:
PORT_CONFIG[] portCfg = new PORT_CONFIG[12];
// ...Initialize code goes here
dig704.PortConfig(portCfg, true);
但是当调用方法时程序会抛出异常。我做错了什么?
例外是:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
如果我尝试以下操作,可以获得更多信息:
IntPtr pointer = Marshal.GetITypeInfoForType(typeof(PORT_CONFIG));
我收到的例外是:
The specified type must be visible from COM.\r\nParameter name: t
【问题讨论】:
-
帮助我们帮助您 Gary - 异常详细信息是什么?
标签: c# com parameter-passing