473,326 Members | 2,114 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,326 software developers and data experts.

Importing a DLL function

Hi,

I've run into a problem with exporting and importing a function from a DLL.
Hopefully somebody here can tell me how this should be done properly.

My DLL function is as follows:
void DoSomething();

This would be exported using a DEF file.

The calling application links to my DLL dynamically, and does something like
this in order to import and call the function:
typedef void (*DOSOMETHINGTYPE)();
HANDLE hDll = LoadLibrary(...);
DOSOMETHINGTYPE DoSomethingPtr = (DOSOMETHINGTYPE)GetProcAddress(hDll,
"DoSomething");
DoSomethingPtr();
Now, I would like to change my exported function to be defined as follows:
extern "C" __declspec(dllexport) void __stdcall DoSomething();

Then, how do I need to typedef the function in the calling app? I've tried a
few variations on the following, but I get loads of compiler errors:
typedef extern "C" __declspec(dllimport) void __stdcall
(*DOSOMETHINGTYPE)();

I am using the Microsoft Visual C++ compiler here.

Can anybody help me?
Cheers,
HF
Jul 23 '05 #1
3 7909
Use:

typedef void ( __stdcall *DOSOMETHINGTYPE)();
"Halvdan Friis" <th**@address.is.invalid> wrote in message
news:tx********************@news2.e.nsc.no...
Hi,

I've run into a problem with exporting and importing a function from a DLL. Hopefully somebody here can tell me how this should be done properly.

My DLL function is as follows:
void DoSomething();

This would be exported using a DEF file.

The calling application links to my DLL dynamically, and does something like this in order to import and call the function:
typedef void (*DOSOMETHINGTYPE)();
HANDLE hDll = LoadLibrary(...);
DOSOMETHINGTYPE DoSomethingPtr = (DOSOMETHINGTYPE)GetProcAddress(hDll,
"DoSomething");
DoSomethingPtr();
Now, I would like to change my exported function to be defined as follows:
extern "C" __declspec(dllexport) void __stdcall DoSomething();

Then, how do I need to typedef the function in the calling app? I've tried a few variations on the following, but I get loads of compiler errors:
typedef extern "C" __declspec(dllimport) void __stdcall
(*DOSOMETHINGTYPE)();

I am using the Microsoft Visual C++ compiler here.

Can anybody help me?
Cheers,
HF

Jul 23 '05 #2

"Nahappan SM" <sm*****@hotmail.com> wrote in message
news:Ry*****************@news.cpqcorp.net...
Use:

typedef void ( __stdcall *DOSOMETHINGTYPE)();


No need for the -- extern "C" __declspec(dllimport) -- then? Why not?

- HF
Jul 23 '05 #3
If you had the header file of the class that you want to use then it would
anyway contain the extern "C" __declspec (dllimport), through conditional
compilation. Since you want to get the function pointer at runtime, you just
need to declare the function pointer. The signature then does not need to
know how the function has been exported. Just the calling convention is
enough.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: python | last post by:
I'm writing a function and it needs to use regular expressions and the super-fantastic mx.DateTime module. The first lines after the doc string in the function are: import re, mx.DateTime ...
11
by: Jeff Wagner | last post by:
I am importing a file which contains a persons name (firstName, middleName, etc). If I define a function to do this, how can I use the variables outside of that function? Here is the code: ...
1
by: J. Kenney | last post by:
Good Morning, Is there a way for a function called within an _imported_ library to call back to _calling_ python program to run a function? (Shown below) Also can you overload the print...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
3
by: Mark | last post by:
All, As you can see below, I have had problems with inquisitive souls looking at data they shouldn't be. I though disabling the ability to create new databases using my workgroup would stop this...
5
by: dixie | last post by:
If I sent a user an empty database container - dB with no tables and I needed them to import their tables into it and one of their tables was a hidden table with the prefix Usys, is there any way...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
5
by: BeruthialsCat | last post by:
First go with trying to import xml to a database and whilst i have managed to do what i want i find that the xml files we have here at work are gonna cause me problems. I have a function that...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.