Importing a DLL function


H

Halvdan Friis

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
 
Ad

Advertisements

Ad

Advertisements

N

Nahappan SM

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top