Re-exporting functions from dynamically linked DLL



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?


.



Relevant Pages

  • Re: Forward declarations
    ... >Can I forward-declare MyStruct somehow? ... can I forward declare a typedef or an enum? ... I would hope that any such header file gives you a documented way to /use/ ... with, perhaps, some preprocessor (or typedef) hackery of your own. ...
    (comp.lang.cpp)
  • Re: Exported function mangaled name
    ... that header file; it must be declared as __declspec ... You have to declare the function the same way in your .cpp file as in ... #define LIBSPEC __declspec ... See my essay on The Ultimate DLL Header File on my MVP Tips site. ...
    (microsoft.public.vc.mfc)
  • Re: make general windows module
    ... The VB version of these declarations is the "Declare Statement". ... mimicing the behavior of a "windows.h" header file for VB. ... not all Windows API calls can be called from VB as some use reference ...
    (microsoft.public.vb.general.discussion)
  • Re: confused about extern use
    ... going to achieve by declaring it as extern in the header file a.h. ... composed on one or more compilation units. ... Essentially you *declare* the type wherever it is ...
    (comp.lang.c)
  • Re: Trouble with FILE
    ... reasons I had to split up this program in several modules. ... I can declare, ... extern FILE *fp1; ... included in the header file, so that the FILE type is defined. ...
    (comp.lang.c)