Re: VS2010 and HINSTANCES
"David Webber" <dave@musical-dot-demon-dot-co.uk> wrote in message
news:OHAD2ovALHA.1700@TK2MSFTNGP02.phx.gbl...
The static handle to the language DLL *is* initialised to NULL where the
static member is declared. But that may not be happening - static stuff
isn't always initialised when you declare
static MYCLASS::x = 0;
We'll see. But it is the destructor which is trying to reset an
uninitialised handle, so I'm not yet sure.
Initializing static variables has worked reliably for me. But the
0xcccccccc is said to be used for *local* variables, not static members.
I'm not sure if that is significant, but it may mean the scope of your
variable is not what it appears to be?
In my new solution, I thought I'd take advantage of zappy new project
possibilities - specifically a tabbed MDI interface with a navigation pane
down the left (not sure about the calendar though). Long before the
program knows about View windows, it is initialising the navigation pane.
Somewhere in the middle of this, my resource handle manager class is
getting called (to try and set the "Folders" title in the new navigation
pane to the desired language"), and it is only initialised later. (I
haven't looked at the initialisation didn't explicitly ask it to do this,
but clearly my MainFrame code knows better than I do that this would be
wanted.) I am not sure (I'll find out after breakfast) if
AfxGetResourceHandle() is returning 0xcccccccc - hope not, it wouldn't
seem logical - or if it is screwing up in some other way, but *of course*
I'll try and put a stop to it.
I would set a breakpoint in your resource class and view the callstack when
it is accessed the first time to see if you can call your Init method prior
to all this starting. It would seem one of the first things to do in your
InitInstance().
You could also set a data breakpoint on the static hInst variable changing.
//------
Back to the initial point:
Meanwhile, as I say, it would be defensive programming to have
if( IsValidHinstance(hInst) ) AfxSetResourceHandle( hInst );
instead of
if( hInst ) AfxSetResourceHandle( hInst );
This would mean folk wanting other languages would get their menus in
English, instead of a program crash. That was all I was asking.
The answers here seem to indicate that there might not be one - I didn't
find it in the help system either, though I'm finding it more difficult
than ever to find anything in the VS 2010 help system. (Which is maybe
why no-one has categorically said that there isn't one <g>.)
I looked very hard but couldn't find one. I think once I wrote something
like:
if ( hInst && hInst != 0xcccccccc )
AfxSetResourceHandle(hInst);
Which fixed my logic but of course I went back and cleaned that up prior to
shipping. BTW, does your code work OK in Release mode (where uninitialized
variables are left uninitialized and not set to 0xcccccccc)? I would think
it would work randomly well based on whether hInst happened to be
initialized to 0 or not.
-- David