Re: Load a DLL procedure
"dushkin" <taltene@gmail.com> wrote in message
news:996d7b1c-7d23-4a09-905e-9a43f215563d@e16g2000yqc.googlegroups.com...
Hi,
For example, I succeed to load lr_message procedure:
----------------------------------------------------------
From the DLL h file:
#if defined(cplusplus) || defined(__cplusplus)
extern "C" {
#define PROTO(x) x
#endif
#ifdef _WIN32
/* LR_FUNC is used for the call-back functions of the compiled Vuser
*/
#define LR_FUNC CALLBACK
/* LR_MSG_FUNC is used for the message functions */
#define LR_MSG_FUNC WINAPIV
#else
#define LR_FUNC __export WINAPI
#define LR_MSG_FUNC FAR CDECL __export
#endif
int LR_MSG_FUNC lr_message PROTO((LPCSTR fmt, ...));
}
And it is fine.
It is fine because after the preprocessor is run, lr_message has the
__export keyword in front of it, so it is actually exported from the DLL.
But, for other functions, on the same DLL I fail. For example:
----------------------------------------------------------
From the DLL h file:
int WINAPI lr_save_string PROTO((const char * param_val, const char *
param_name));
And I get the message box.
Why?
Because WINAPI doesn't have __export in the definition and so lr_save_string
is not exported. You can use the included utility "DUMPBIN.EXE /exports"
which comes with VC++ to actually get a text dump of the exported functions
in a DLL.
I encourage you to use __declspec(dllexport) for all your exported functions
as this is the way modern VC++ does it. A common pattern is in your DLL.H
file:
#ifdef BUILDING_DLL
#define DLLFUNC __declspec(dllexport)
#else
#define DLLFUNC __declspec(dllimport)
and when building the DLL, define BUILDING_DLL in the C++ preprocessor
definitions of the project so that those functions are exported. It won't
be defined in the .exe using the DLL, so those functions will be imported.
(Substitute BUILDING_DLL with a more specific name for your DLL so that all
your DLL's have unique names for this and don't all use BUILDING_DLL).
-- David