G
Guest
I have following structure in c++.
typedef struct MMF_result_struct
{
int action;
char text[1024];
int cols,rows;
int month,day,year;
} MMF_result;
Now this structure is shared between C++ and C# using memory mapped file. We already have C++ code for handling memory mapped file. I am working on converting code for memory mapped file in C#. Now I have to pass pointer to the above structure. I converted this structure to C# as follows:
[StructLayout(LayoutKind.Sequential)]
public struct MMF_result_struct
{
public int action;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=1024)]
public char[] a1;
public int cols;
public int rows;
public int month;
public int day;
public int year;
}
I am not able to determine size of the structure using sizeof operator. Also I am not able to typecast the void * pointer returned from memory mapped file back to above structure pointer. It says "Cannot take the address or size of a variable of a managed type ('MMF_result_struct') ". I dont know why when a char array is included in structure it starts treating structure as managed type. If we exclude the character array it works fine.
Any help related to this would be highly appreciated.
Vikas
typedef struct MMF_result_struct
{
int action;
char text[1024];
int cols,rows;
int month,day,year;
} MMF_result;
Now this structure is shared between C++ and C# using memory mapped file. We already have C++ code for handling memory mapped file. I am working on converting code for memory mapped file in C#. Now I have to pass pointer to the above structure. I converted this structure to C# as follows:
[StructLayout(LayoutKind.Sequential)]
public struct MMF_result_struct
{
public int action;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=1024)]
public char[] a1;
public int cols;
public int rows;
public int month;
public int day;
public int year;
}
I am not able to determine size of the structure using sizeof operator. Also I am not able to typecast the void * pointer returned from memory mapped file back to above structure pointer. It says "Cannot take the address or size of a variable of a managed type ('MMF_result_struct') ". I dont know why when a char array is included in structure it starts treating structure as managed type. If we exclude the character array it works fine.
Any help related to this would be highly appreciated.
Vikas