2012-05-17 61 views
0

我用以下聲明的IDL文件中的COM接口:傳遞結構數組的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 
+1

什麼是例外? –

+1

幫助我們幫助你加里 - 什麼是例外細節? – n8wrl

回答