H
hykim
I want to call a unmanaged dll's function returning some STRUCT's pointer.
the next is definition of a STRUCT.
-----------------------------------------------------------------------
typedef struct myStruct{
struct {
UINT_PTR anything;
UCHAR anything2[(10*sizeof(ULONG))+1];
} myInnerStruct;
UCHAR anything3[(6*sizeof(ULONG))+1];
ULONG anything4;
} MYSTRUCT, * MYSTRUCT;
-----------------------------------------------------------------------
I defined managed structure as below.
-----------------------------------------------------------------------
[StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi)]
private struct MYSTRUCT
{
struct myInnerStruct
{
public UIntPtr anything;
[MarshalAs(UnmanagedType.AnsiBStr, SizeConst=41)]
unsafe public byte[] anything2;
}
[MarshalAs(UnmanagedType.AnsiBStr, SizeConst=25)]
byte anything3;
int anything4;
}
-----------------------------------------------------------------------
the next is definition of funtions inclued in unmanaged dll.
-----------------------------------------------------------------------
MYSTRUCT* foo1();
void foo2(MYSTRUCT* paStruct);
-----------------------------------------------------------------------
and, the next is my code for marshaling that funtions.
-----------------------------------------------------------------------
[DllImport("mydll.dll", EntryPoint="foo1", CharSet=CharSet.Ansi)]
[return : MarshalAs(UnmanagedType.Struct] -------------------- 1)
public static extern MYSTRUCT* firstFoo(); ---------------------- 2)
[DllImport("mydll.dll", EntryPoint="foo2", CharSet=CharSet.Ansi)]
public static extern void secondFoo(ref MYSTRUCT myStruct1); ----- 3)
-----------------------------------------------------------------------
but, they are not work correctly. What is worse, It raise compile errors
meaning that
can't get variable address or size of managed types.
How can I solve this problem??
Plz. Help Me!! =.=;
the next is definition of a STRUCT.
-----------------------------------------------------------------------
typedef struct myStruct{
struct {
UINT_PTR anything;
UCHAR anything2[(10*sizeof(ULONG))+1];
} myInnerStruct;
UCHAR anything3[(6*sizeof(ULONG))+1];
ULONG anything4;
} MYSTRUCT, * MYSTRUCT;
-----------------------------------------------------------------------
I defined managed structure as below.
-----------------------------------------------------------------------
[StructLayout( LayoutKind.Sequential, CharSet=CharSet.Ansi)]
private struct MYSTRUCT
{
struct myInnerStruct
{
public UIntPtr anything;
[MarshalAs(UnmanagedType.AnsiBStr, SizeConst=41)]
unsafe public byte[] anything2;
}
[MarshalAs(UnmanagedType.AnsiBStr, SizeConst=25)]
byte anything3;
int anything4;
}
-----------------------------------------------------------------------
the next is definition of funtions inclued in unmanaged dll.
-----------------------------------------------------------------------
MYSTRUCT* foo1();
void foo2(MYSTRUCT* paStruct);
-----------------------------------------------------------------------
and, the next is my code for marshaling that funtions.
-----------------------------------------------------------------------
[DllImport("mydll.dll", EntryPoint="foo1", CharSet=CharSet.Ansi)]
[return : MarshalAs(UnmanagedType.Struct] -------------------- 1)
public static extern MYSTRUCT* firstFoo(); ---------------------- 2)
[DllImport("mydll.dll", EntryPoint="foo2", CharSet=CharSet.Ansi)]
public static extern void secondFoo(ref MYSTRUCT myStruct1); ----- 3)
-----------------------------------------------------------------------
but, they are not work correctly. What is worse, It raise compile errors
meaning that
can't get variable address or size of managed types.
How can I solve this problem??
Plz. Help Me!! =.=;