[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: OT dll-hell where to find help
- From: "Jerome Vuarand" <jerome.vuarand@...>
- Date: Mon, 21 Apr 2008 10:45:24 -0400
Wesley Smith wrote:
> Thanks for the response. This was exactly my understanding, but
> somehow this is not what I'm experiencing. For example, to even back
> away from C++ into C I have this code:
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> extern __declspec(dllexport) int t1;
> extern __declspec(dllexport) int *t2;
>
> #ifdef __cplusplus
> }
> #endif
>
> Then in the .cpp file I have
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> __declspec(dllexport) int t1 = 6969;
> __declspec(dllexport) int *t2 = 0;
>
> #ifdef __cplusplus
> }
> #endif
>
> When I look at these vars in the debugger, I get absolute garbage and
> when I try to write to them, I get crashes from access violations.
> This is with VS2008 and my project set to a dll build. I don't think
> there's anything particularly wrong with my code. <sigh>
When accessing these variables from the other module, you have to make
sure they are declared with dllimport attribute. One way to do that is
to use MACROS:
// mydll.h
#ifdef BUILDING_MY_DLL
#define MY_DLL_API __declspec(dllexport)
#else
#define MY_DLL_API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern MY_DLL_API int t1;
extern MY_DLL_API int *t2;
#ifdef __cplusplus
}
#endif
And define BUILDING_MY_DLL while compiling the module containing the
exported variables, but not when compiling the modules importing them.