J
Johann Blake
I need to call a C DLL function. The first parameter expects a pointer
to a long. It returns a value at the address of the pointer. The second
parameter expects a pointer to a pointer. It creates an array and
returns the data it stores in this array.
I have tried many different combinations of P/Invoke declarations and
none have worked. When I step from my c# code into the c code, oNumRays
points to 0x00000000 and when it attempts to assign a value, an error
gets generated (something about object not set). Here are the
declarations I have tried:
public static extern Char SomeFunction(ref int numberOfRays, IntPtr
rayDirs);
public static extern Char SomeFunction(out int numberOfRays, IntPtr
rayDirs);
public static extern Char SomeFunction(IntPtr numberOfRays, IntPtr
rayDirs);
public static extern Char SomeFunction([MarshalAs(UnmanagedType.U4)]
out int numberOfRays, IntPtr rayDirs);
public static extern Char SomeFunction([MarshalAs(UnmanagedType.U4)]
int numberOfRays, IntPtr rayDirs);
Here is the C function...
static float sRayDirs[8];
GuiInterface_API char SomeFunction(long* oNumRays, float** oRayDirs)
{
*oNumRays = 12;
sRayDirs[0] = 1.1f;
sRayDirs[1] = 2.2f;
sRayDirs[2] = 3.3f;
sRayDirs[3] = 4.4f;
sRayDirs[4] = 5.5f;
sRayDirs[5] = 6.6f;
sRayDirs[6] = 7.7f;
sRayDirs[7] = 8.8f;
*oRayDirs = sRayDirs;
return 0;
}
Any suggestions on how to make this work?
Thanks for your help!
Johann Blake
to a long. It returns a value at the address of the pointer. The second
parameter expects a pointer to a pointer. It creates an array and
returns the data it stores in this array.
I have tried many different combinations of P/Invoke declarations and
none have worked. When I step from my c# code into the c code, oNumRays
points to 0x00000000 and when it attempts to assign a value, an error
gets generated (something about object not set). Here are the
declarations I have tried:
public static extern Char SomeFunction(ref int numberOfRays, IntPtr
rayDirs);
public static extern Char SomeFunction(out int numberOfRays, IntPtr
rayDirs);
public static extern Char SomeFunction(IntPtr numberOfRays, IntPtr
rayDirs);
public static extern Char SomeFunction([MarshalAs(UnmanagedType.U4)]
out int numberOfRays, IntPtr rayDirs);
public static extern Char SomeFunction([MarshalAs(UnmanagedType.U4)]
int numberOfRays, IntPtr rayDirs);
Here is the C function...
static float sRayDirs[8];
GuiInterface_API char SomeFunction(long* oNumRays, float** oRayDirs)
{
*oNumRays = 12;
sRayDirs[0] = 1.1f;
sRayDirs[1] = 2.2f;
sRayDirs[2] = 3.3f;
sRayDirs[3] = 4.4f;
sRayDirs[4] = 5.5f;
sRayDirs[5] = 6.6f;
sRayDirs[6] = 7.7f;
sRayDirs[7] = 8.8f;
*oRayDirs = sRayDirs;
return 0;
}
Any suggestions on how to make this work?
Thanks for your help!
Johann Blake