By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,448 Members | 1,412 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,448 IT Pros & Developers. It's quick & easy.

problem: DllImport a C function returning opaque pointer

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Kurt Ng" <hs**@excite.com> wrote in message
news:ub**************@TK2MSFTNGP09.phx.gbl...
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

Nov 15 '05 #2

P: n/a
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
"Justin Rogers" <Ju****@games4dotnet.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.