Re-exporting functions from dynamically linked DLL

K

Kevin Crosbie

Hi,

I have the following situation:

I have a 3rd party DLL which does not include a LIB file, just a header file
with typedef declarations for exported functions (It is intended for dynamic
linking)

I need to wrap the DLL to allow for callbacks to my own code (in Lisp), and
to do this I need to load the DLL using LoadLibrary and access each function
that I need using GetProcAddress.
So for example:

The third party header will say:
typedef INT (WINAPI * lp_function)();

Then in my c wrapper file:
#include "3rdparty.h"

#ifdef _WIN32
#define DllExport __declspec(dllexport)
#else
#define DllExport
#endif

HINSTANCE hInstance;
lp_function f1;

DllExport int initialiseAPI()
{
if(NULL==(hInstance=LoadLibrary("demoapi.dll")))
{
return 1;
}

if(NULL==(f1=(lp_function)GetProcAddress(hInstance,"function")))
{
return 1;
}

}

etc.

The I implement the callback code which in turn calls code on my Lisp side.

So my question is:
I want to re-export these dynamically linked functions. I could easily
wrap them:

DllExport void wrappedf1 (int arg)
{
f1(arg);
}

but I would prefer to just declare it as exported somehow. If I try
something like changing their header file to say:
typedef DllExport INT (WINAPI * lp_function)();

and my code to declare:
DllExport lp_function f1;

I get a Segmentation Violation.

Anyone have any ideas?
 
V

Victor Bazarov

Kevin said:
I have a 3rd party DLL which does not include a LIB file, just a header file
with typedef declarations for exported functions (It is intended for dynamic
linking)

I need to wrap the DLL to allow for callbacks to my own code (in Lisp), and
to do this I need to load the DLL using LoadLibrary and access each function
that I need using GetProcAddress.

[...]
Anyone have any ideas?

Wrong newsgroup. DLLs are not part of C++ language, they are quite
platform-specific. Post to comp.os.ms-windows.programmer.win32 or to
a newsgroup for your C++ compiler.

V
 
K

Kevin Crosbie

Victor Bazarov said:
Wrong newsgroup. DLLs are not part of C++ language, they are quite
platform-specific. Post to comp.os.ms-windows.programmer.win32 or to
a newsgroup for your C++ compiler.

V

Will do. Thanks Victor.
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top