problem: DllImport a C function returning opaque pointer

  • Thread starter Thread starter Kurt Ng
  • Start date Start date
K

Kurt Ng

Hi, y'all.

Can anyone help me on this problem?

I'm working with a third-party C dll, and I'm having trouble importing into
C# the dll's methods that return one of the dll's defined types, which are
all defined as opaque pointers. What I tried to do is use IntPtr for the
opaque pointer return type, but there seems to be a resulting signature
problem.

C example:
typedef struct _Control *Control; // type
Control controlCreate(long type, long address); // function
long controlValidate(Control control); // another function
long controlInit(Control control); // another function

C# declaration:
[DllImport("myDll")]
static extern IntPtr controlCreate(int type, int address);
[DllImport("myDll")]
static extern int controlValidate(IntPtr control);
[DllImport("myDll")]
static extern int controlInit(IntPtr control);

C# execution:
int retval;
private IntPtr mycontrol;
mycontrol = controlCreate(0, 0); // ok
retval = controlValidate(mycontrol); // ok
retval = controlInit(mycontrol); // gets EntryPointNotFoundException

This seems to work fine, except for an entry point exception. The second
and third functions have the same signatures, but only the third function
call could not find the entry point from the dll.

Why is there a signature problem with two nearly identical function
prototypes?
Is the IntPtr correctly used for the function returns in this situation?
Is there a better way to do what I'm trying to do?
Do I have a fubar-ed dll?

TIA,
Kurt
 
You should use your DumpBin /exports to find out if your function names properly
match with those
in the dll and make sure the function prototypes really do match.
 
Great! This advice really helped. Dumpbin showed that the function at
fault had no entry point. that function was actually wrapping a different
function; the documentation that I have did not mention this. I have the
correct function imported now. Thanks very much. :)

Kurt
 
Back
Top