[C#] Comment declarer un pointeur Unsafe pour une structure?
Bonjour,
J'ai essaie de compiler le code suivant :
Code:
1 2 3 4 5 6 7 8 9
|
somedata = new Byte[1024];
unsafe
{
fixed ( byte *pData = somedata)
{
MY_STRUCT1* ptr = (MY_STRUCT1*)pData;
} |
mais le compilateur sort avec l'erreur suivante :
Citation:
Error 38 Cannot take the address of, get the size of, or declare a pointer to a managed type MY_STRUCT1 ...
sur la ligne avec l'initialisation du pointer ptr.
La structure MY_STRUCT1 :
Code:
1 2 3 4 5 6 7 8 9 10
|
[Serializable]
[StructLayout(LayoutKind.Sequential, Pack=1)]
public struct MY_STRUCT1 {
int par1;
int par2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte [] abParamVal;
} |
Si la structure ne contient pas la ligne avec le byte-array abParamVal, ca compile.
Est-ce il y a une explication pour ca ?
Merci d'avance.
Abra