0

a similar problem is posted many times here but I cannot figure out why I get this COM Exception.

I have an IDL file like:

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);

}; 

Now, TMask struct contains a TAction field.

I create a interop assemply with tlbimp (without /sysarray arg) and the signature for IDecoToniConfig.set_Masks() is :

public virtual void set_masks(ref DecoToniCfgLib.TMask[] value)

But when I call it from c# side using:

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);

I get:

System.ArgumentException

"One or more arguments are not valid. (HRESULT: 0x80070057 (E_INVALIDARG))"

Why?

Barzo
  • 1,039
  • 1
  • 11
  • 37

1 Answers1

0

As suggested here I change my code turning the structs into COM interfaces.

Also I noted that interoperability has some drawbacks using interface inheritance (eg two Interfaces which derives from another one).

Community
  • 1
  • 1
Barzo
  • 1,039
  • 1
  • 11
  • 37