Re: CRITICAL_SECTION not initialized globally in DllMain
- From: "m" <m@xxx>
- Date: Mon, 6 Jul 2009 18:37:17 -0400
As you have discovered, declaring variables in header files is a bad idea. In this case, the same header file being included in multiple compilation units (.c or .cpp source files) causes multiple declarations of the same variable; unless, as when you specified static, the declarations are local scope (internal linkage) to the compilation unit. To find out more, read the C or C++ spec or some of the commentary in MSDN.
"Fabian" <Fabian@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:7C4EE0DA-B153-43D9-B8F3-B8BF56E894D9@xxxxxxxxxxxxxxxx
Actually I solved it. I forgot to define it:
declaration in header file:
extern "C" CRITICAL_SECTION csCalibrate;
definition in cpp file:
CRITICAL_SECTION csCalibrate;
"Fabian" wrote:
Hi Roger,
"rogero" wrote:
> On Jul 6, 3:00 pm, <dan...@xxxxxxxxxxxxxxxx> wrote:
> > What is the point of declaring a static variable if it's already > > global.
> > Does static global not mean it's valid only in the context of the > > same
> > source file ?
>
> It means each source file gets it's *own* copy of the variable.
> This, I believe, explains the AV - the variable that gets initialised
> is in one source file and is a *different* variable to the one in the
> FindRotationCenter.
>
> Roger.
>
If I only declare it global in the header file the linker strikes:
Error 1 error LNK2005: "struct _RTL_CRITICAL_SECTION csCalibrate"
(?csCalibrate@@3U_RTL_CRITICAL_SECTION@@A) already defined in
dllmain.obj FindRotationCenter.obj BeadAlignment
How else do I solve this?
Thx,
Fabian
.
- Follow-Ups:
- References:
- CRITICAL_SECTION not initialized globally in DllMain
- From: Fabian
- Re: CRITICAL_SECTION not initialized globally in DllMain
- From: daniel
- Re: CRITICAL_SECTION not initialized globally in DllMain
- From: rogero
- Re: CRITICAL_SECTION not initialized globally in DllMain
- From: Fabian
- Re: CRITICAL_SECTION not initialized globally in DllMain
- From: Fabian
- CRITICAL_SECTION not initialized globally in DllMain
- Prev by Date: Re: Impersonation and BackupWrite
- Next by Date: Re: Unexpected Behavior with private Heaps (HeapCreate, HeapWalk, HeapDestroy)
- Previous by thread: Re: CRITICAL_SECTION not initialized globally in DllMain
- Next by thread: Re: CRITICAL_SECTION not initialized globally in DllMain
- Index(es):
Relevant Pages
|