lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Apr 21, 2008 at 1:25 AM, Ben Harper <rogojin@gmail.com> wrote:
> There is nothing particularly strange about it. Static class data is
>  just like static C data. It lives within a compilation unit, which is
>  basically a single .CPP file. If you use the correct
>  __declspec(dllexport) / __declspec(dllimport) declaration on your
>  class, then you shouldn't have a problem. Perhaps your static data
>  needs to be initialized? Does your static data have a non-trivial
>  constructor? If so, then you must realize that these constructors are
>  run by the DLL loader, which is built into your DLL by the linker. You
>  must take care not to use such objects until after the DLL loader has
>  finished running.


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>

wes