[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: OT dll-hell where to find help
- From: "Ben Harper" <rogojin@...>
- Date: Mon, 21 Apr 2008 11:24:39 +0200
Can you post the code used to access the variables, and is it from
another DLL or an EXE?
On Mon, Apr 21, 2008 at 10:36 AM, Wesley Smith <wesley.hoke@gmail.com> wrote:
> 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
>