Click here to Skip to main content
15,888,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the *.idl content

C++
[uuid(C3BBAEE5-DC4A-4873-963B-EFDAC87FC443)]
typedef enum
{
eVal1 =1,
eVal2 =2
}EData1;


[uuid(1B790A2A-9F6F-4F03-A54F-993B52D507A6)]
struct STData1
{
      EData1     ed1;
      float      fValue[15];
}

[uuid(AA612D65-AE0E-4C51-9A35-79A76FF20747)]
struct STData2
{
   long long      tTimeStamp;
   struct STData1 tData[16];
};


in C# refering the dll containing these structures,But getting

C#
[Serializable]
       [SuppressUnmanagedCodeSecurity]
       [Guid("AA612D65-AE0E-4C51-9A35-79A76FF20747")]
       public struct STData2
       {
           public STData1[] tData;
           public long tTimeStamp;
       }

See above, STData1 not carrying the length 16.Please help.

thanks in advance.
Posted

1 solution

Have a look at Default Marshaling for Arrays[^] on MSDN - there's an example of what you're trying to do at the bottom:
C#
[Serializable]
[SuppressUnmanagedCodeSecurity]
[Guid("AA612D65-AE0E-4C51-9A35-79A76FF20747")]
public struct STData2
{
    public long tTimeStamp;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
    public STData1[] tData;
}

NB: The order of the fields in the C# structure needs to match the order of the fields in the C++ structure.
 
Share this answer
 
v2
Comments
shankha2010 23-Nov-15 4:54am    
Hi Thanks for your reply.
I need to do something from C++ side [idl,struct STData1 etc.] so that "[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]" get appended in the C# side autometically without myself putting it manually.

something like:
*.idl
[uuid(AA612D65-AE0E-4C51-9A35-79A76FF20747)]
struct STData2
{
long long tTimeStamp;
something here=""
struct STData1 tData[16];
};

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900