> Hi TomR,
>
[quoted text clipped - 10 lines]
> Yanhong Huang
> Microsoft Community Support
Thanks to all the replies. With everyone's assistance I have managed to
track down the culprit in the loading of the DLL, but now I'm not quite sure
why this isn't working (no change from vc6 where it was working).
The error occurs during initialization but before DllMain gets called. In
the construction of a class, the function foo() gets called (obviously pared
way down).
It appears scutTable isn't being initialized. Any attempt to access it or
any members causes an access violation.
Do you have any idea why this behavior has changed and suggestions on the
best way to get the initialization to happen? Should I create a static
function to initialize it?
Thanks,
TomR
static struct Entry {
CString str;
UINT mod;
Entry(LPCTSTR a_str, UINT a_mod)
{
str = a_str;
mod = a_mod;
}
} scutTable[] = {
Entry("Alt+", FALT),
Entry("Ctrl+", FCONTROL),
Entry("Shift+", FSHIFT),
Entry("LButton+", FLBUTTON),
Entry("MButton+", FMBUTTON),
Entry("RButton+", FRBUTTON)
};
void foo()
{
CString myEntryString = scutTable[0].str; // Causes access violation
}
Ronald Laeremans [MSFT] - 17 Mar 2005 23:26 GMT
> Thanks to all the replies. With everyone's assistance I have managed to
> track down the culprit in the loading of the DLL, but now I'm not quite sure
[quoted text clipped - 34 lines]
> CString myEntryString = scutTable[0].str; // Causes access violation
> }
How does foo get called before DLLMain is executed? In what translation
unit is the call to foo?
Ronald
tomrmgc - 18 Mar 2005 00:03 GMT
> > Thanks to all the replies. With everyone's assistance I have managed to
> > track down the culprit in the loading of the DLL, but now I'm not quite sure
[quoted text clipped - 39 lines]
>
> Ronald
In one of the class constructors, foo is called (although a few levels down).
I'm not totally sure how to answer the last question. The file
UI_CommandManager.cpp contains a call to foo (which is in UI_HotKeyCtrl.cpp).
Would a copy of the call stack be meaningful?
To followup to my other post, I have another static struct in
UI_HotKeyCtrl.cpp that only contains int's and it gets initialized just fine.
For some reason the CStrings don't get initialized.
TomR
tomrmgc - 17 Mar 2005 23:33 GMT
> > Hi TomR,
> >
[quoted text clipped - 49 lines]
> CString myEntryString = scutTable[0].str; // Causes access violation
> }
Sorry to followup my own post, but I found out a little bit more
information. It appears the CString is not getting initialized. If I have a
static variable that is an int, it gets initialized. If I have a static
variable that is a CString, it does NOT get initialized. Is this
known/expected behavior?
Oleg Starodumov - 21 Mar 2005 10:04 GMT
> Sorry to followup my own post, but I found out a little bit more
> information. It appears the CString is not getting initialized. If I have a
> static variable that is an int, it gets initialized. If I have a static
> variable that is a CString, it does NOT get initialized. Is this
> known/expected behavior?
Yes, the problem seems to be with the order in which the constructors of
global/static objects are called. Probably constructors of some objects
attempt to use other objects _before_ their constructors have been executed
(and thus the objects are not yet initialized).
I would recommend to move the initialization of the DLL's global state
into dedicated functions that should be called by the user of the DLL.
Then you will be able to control the order in which the objects are initialized.
Regards,
Oleg
tomrmgc - 21 Mar 2005 15:11 GMT
> > Sorry to followup my own post, but I found out a little bit more
> > information. It appears the CString is not getting initialized. If I have a
[quoted text clipped - 13 lines]
> Regards,
> Oleg
I agree it appears this is what is happening. I wish Microsoft would have
been a little more proactive in documenting changes such as these. Not only
would it confirm what I'm seeing but it would have prevented me from bashing
my head against a brick wall for the last week.
TomR
Ronald Laeremans [MSFT] - 21 Mar 2005 20:37 GMT
>>>Sorry to followup my own post, but I found out a little bit more
>>>information. It appears the CString is not getting initialized. If I have a
[quoted text clipped - 20 lines]
>
> TomR
Statics in one compiland are initialized in the order they are
encountered. Statics accross compilands ar initialized in what is
essentially a random order. There are directives that normally make sure
CRT and other libraries initialize first (see #pragma init_seg).
In short the code probably has a dependency on undefined behavior and
undefined behavior does change between versions.
Ronald Laeremans
Visual C++ team