类似的问题在这里多次发布,但我无法弄清楚为什么我会得到这个COM异常。
我有一个IDL文件,如:
typedef [uuid(A6F30630-53F5-4688-829A-C084BA1C7DC0)]
enum EMaskActions
{
....
}EMaskActions;
typedef [uuid(A6F30632-53F5-4688-829A-C084BA1C7DC0)]
enum EMaskCallType
{
....
}EMaskCallType;
typedef [uuid(A6F30640-53F5-4688-829A-C084BA1C7DC0)]
struct TAction
{
EMaskActions Action;
BSTR Message;
long ExData;
}TAction;
typedef [uuid(A6F30641-53F5-4688-829A-C084BA1C7DC0)]
struct TMask
{
EMaskCallType CallType;
BSTR MaskString;
TAction Action;
}TMask;
[
object,
uuid(A6F30650-53F5-4688-829A-C084BA1C7DC0),
oleautomation,
nonextensible,
helpstring("DecoToniConfig Interface"),
pointer_default(unique)
]
interface IDecoToniConfig : IUnknown
{
....
[propget, id(6), helpstring("Returns the masks")]
HRESULT Masks([out, retval] SAFEARRAY(TMask)* masks);
[propput, id(6), helpstring("Sets the masks")]
HRESULT Masks([in, out] SAFEARRAY(TMask)* masks);
};
现在,TMask结构包含一个TAction字段。
我用tlbimp(没有/ sysarray arg)创建一个interop assemply,IDecoToniConfig.set_Masks()的签名是:
public virtual void set_masks(ref DecoToniCfgLib.TMask[] value)
但是当我从c#侧使用:
调用它时TMask[] masks = new TMask[1];
masks[0].CallType = EMaskCallType.MSKD_ACK;
masks[0].MaskString = "12DDD#34MMM";
masks[0].Action = new DecoToniCfgLib.TAction();
_DecotoniConfig.set_masks(ref masks);
我明白了:
System.ArgumentException
"One or more arguments are not valid. (HRESULT: 0x80070057 (E_INVALIDARG))"
为什么?