Hi All,
I have a serious problem here which is bugging me for past few days.
I have a native DLL(Win32), and it exposes only on function called
GetFunctionList
Now this function takes a pointer to pointer of a Structure as an argument.
The Structure is something like
struct func_pointer_list{
void (*fnA)(int a,int b);
int (*fnB)(float a, double b);
}
Now I have to write an Wrapper for this Native DLL in C#.
What I did was I wrote an Structure in C# containing some delegates like this....
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void pfnA(int a, int b)
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate int pfnA(float a, double b)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct func_pointer_list
{
public pfnA fnA;
public pfnB fnB;
}
Now I call this Function called GetFunctionList something like this:
using FUNCTION_LIST_PTR_PTR = System.IntPtr;
[DllImport("NATIVE.DLL", CharSet = CharSet.Ansi)]
public extern static void C_GetFunctionList(ref FUNCTION_LIST_PTR ppFunctionList);
in Code file:
System.IntPtr pp = System.IntPtr.Zero;
myClass.C_GetFunctionList(ref pp);
func_pointer_list fnList = (func_pointer_list)Marshal.PtrToStructure(pp, typeof(func_pointer_list));
I get the Exception 'InvalidFuctionPointerInDelegate' in the Second line (Marshel) saying
"Invalid function pointer 0x1a201000 was passed into the runtime to be converted to a delegate. Passing in invalid function pointers to be converted to delegates can cause crashes, corruption or data loss."
Do any of you have any clue as to what is the right method of doing this.....
Where am I wrong doing this...
Does the above code not gonna work...
Thanx in Advance