A
Abra
Hi,
I try to compile the following code (Visual Studio .NET 2005) :
....
somedata = new Byte[1024];
unsafe
{
fixed ( byte *pData = somedata)
{
MY_STRUCT1* ptr = (MY_STRUCT1*)pData;
}
...
, but I get the following error mesasge from compiler :
Error 38 Cannot take the address of, get the size of, or declare a
pointer to a managed type MY_STRUCT1 ...
on the line with the assignment of the ptr pointer.
Here is how MY_STRUCT1 looks like :
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct MY_STRUCT1 {
int par1;
int par2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte [] abParamVal;
}
If I dont have the line with the abParamVal byte-array in the structure,
everything is fine for the compiler.
Can someone please explain why this does not work ?
Thanks in advance.
Abra
I try to compile the following code (Visual Studio .NET 2005) :
....
somedata = new Byte[1024];
unsafe
{
fixed ( byte *pData = somedata)
{
MY_STRUCT1* ptr = (MY_STRUCT1*)pData;
}
...
, but I get the following error mesasge from compiler :
Error 38 Cannot take the address of, get the size of, or declare a
pointer to a managed type MY_STRUCT1 ...
on the line with the assignment of the ptr pointer.
Here is how MY_STRUCT1 looks like :
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct MY_STRUCT1 {
int par1;
int par2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte [] abParamVal;
}
If I dont have the line with the abParamVal byte-array in the structure,
everything is fine for the compiler.
Can someone please explain why this does not work ?
Thanks in advance.
Abra