473,416 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

problem: DllImport a C function returning opaque pointer

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
2 5274
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jason | last post by:
Hello, I am using Dev c++ to create a dll in c++ on windows xp pro. It provided me with a template and I added a simple function to return an int as a test. It compiled the dll ok and I added a...
3
by: Webdiyer | last post by:
I want to integrate SecurID two-factor authentication system of the RSASecurity.inc into our asp.net application,but I get into trouble when trying to call the API functions of the ACE Agent,I got...
0
by: sqcliu | last post by:
I encounter a strange problem using platform invoke using C#. The senario is this: I have a dll which uses a 3rd party static link library (lib). Inside the lib, there are some C structures...
1
by: Nikolay Petrov | last post by:
I use some of Windows Terminal Services APIs in my app. The is an API function which enumerates sessions on a terminal server. It uses a pointer from another API function to know on which...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
7
by: justin.kruger | last post by:
I am having a problem with exchanging handles with c# and the "CP210xManufacturing.dll" in a device wrapper that i am working on. I have created a wrapper class to address some of the functions...
18
by: chankl | last post by:
Can anyone explain what's an opaque pointer and how it's implemented in C? I read about this concept in the book "C interfaces and implementations". Here's an example from the book (list.h -...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
8
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so I can call up a function written in C++ as unmanaged code and compiled as a dll us vs2005. My application is able to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.