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: 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: What this mean? Compiler output
    ... This probably means that you have multiple declaration of the ... And then a C source file includes both, the typedef for ccc will be ... any single header file more than once, ...
    (comp.lang.c)
  • Re-forward declaration of types which were already forward declared
    ... Is it a good style to re-forward declare the types, ... forward declared in base header file, in derived class header file? ...
    (comp.lang.cpp)