D
dogalacar
Hi All,
I am trying to pass array of structures from a C dll to C# as msdn
sample does(outarrayofstructs sample) but PtrToStructure function gives
error :
--> "structure must not be a value class"
What i am doing wrong ?
here is the code
c code:
typedef struct st2
{
long tt;
} st3;
long ornekfonk(st3 **str)
{
*str = (st3*)CoTaskMemAlloc( 3 * sizeof( st3 ));
(*str)[0].tt = 9;
(*str)[1].tt = 10;
(*str)[2].tt = 11;
return 1;
}
c# code:
[ StructLayout( LayoutKind.Sequential , CharSet=CharSet.Ansi)]
public struct str1
{
public int tt;
}
[DllImport(@"C:\WINDOWS\system32\MapiDll.dll")]
public static extern int ornekfonk( ref IntPtr ptr);
str = new str1();
IntPtr ptr=(IntPtr)0;
ornekfonk(ref ptr);
Marshal.PtrToStructure( ptr, str ); //it gives error here
Thanks in advance
Dogal Acar
I am trying to pass array of structures from a C dll to C# as msdn
sample does(outarrayofstructs sample) but PtrToStructure function gives
error :
--> "structure must not be a value class"
What i am doing wrong ?
here is the code
c code:
typedef struct st2
{
long tt;
} st3;
long ornekfonk(st3 **str)
{
*str = (st3*)CoTaskMemAlloc( 3 * sizeof( st3 ));
(*str)[0].tt = 9;
(*str)[1].tt = 10;
(*str)[2].tt = 11;
return 1;
}
c# code:
[ StructLayout( LayoutKind.Sequential , CharSet=CharSet.Ansi)]
public struct str1
{
public int tt;
}
[DllImport(@"C:\WINDOWS\system32\MapiDll.dll")]
public static extern int ornekfonk( ref IntPtr ptr);
str = new str1();
IntPtr ptr=(IntPtr)0;
ornekfonk(ref ptr);
Marshal.PtrToStructure( ptr, str ); //it gives error here
Thanks in advance
Dogal Acar