From: David Webber on 2 Jun 2010 12:54 I haven't checked it rigorously, but I'm getting the impression that AfxSetResourceHandle() used to be tolerant of getting a NULL HINSTANCE up to VS2008 and no longer is in 2010. It certainly has ASSERT(hInstResource != NULL); now. For a while I got things working by replacing my AfxSetResourceHandle( hInst ) by if( hInst ) AfxSetResourceHandle( hInst ); However, as my project expands, I find I am trying to pass an hInst which the system has cunningly initialised to 0xcccccccc; And it is happening in some very inconvenient call-backs. And it is screwing things up big time! So I need to set the resource handle only if it is valid. Is there a function which tells one whether an HINSTANCE is a valid module? Something like what IsWindow() does for Window handles? I could try ::GetModuleFileName( .... ); but I don't want the name, just to know that it is a proper module. Dave -- David Webber Mozart Music Software http://www.mozart.co.uk For discussion and support see http://www.mozart.co.uk/mozartists/mailinglist.htm
From: David Ching on 2 Jun 2010 13:29 "David Webber" <dave(a)musical-dot-demon-dot-co.uk> wrote in message news:O5rIQRnALHA.4400(a)TK2MSFTNGP05.phx.gbl... > However, as my project expands, I find I am trying to pass an hInst which > the system has cunningly initialised to > > 0xcccccccc; > > And it is happening in some very inconvenient call-backs. And it is > screwing things up big time! > 0xcccccccc is what the debug memory allocator sets uninitialized locals (on the stack) to. This is an error, you should init it to NULL when you allocate it. Otherwise in release build, it is uninitialized! -- David
From: David Lowndes on 2 Jun 2010 13:39 >I haven't checked it rigorously, but I'm getting the impression that >AfxSetResourceHandle() used to be tolerant of getting a NULL HINSTANCE up >to VS2008 and no longer is in 2010. Why are you in the situation of setting the resource handle to NULL - or these invalid values? Dave
From: Joseph M. Newcomer on 2 Jun 2010 17:56 See below... On Wed, 2 Jun 2010 17:54:29 +0100, "David Webber" <dave(a)musical-dot-demon-dot-co.uk> wrote: >I haven't checked it rigorously, but I'm getting the impression that >AfxSetResourceHandle() used to be tolerant of getting a NULL HINSTANCE up >to VS2008 and no longer is in 2010. > >It certainly has > > ASSERT(hInstResource != NULL); > >now. > >For a while I got things working by replacing my > AfxSetResourceHandle( hInst ) >by > if( hInst ) AfxSetResourceHandle( hInst ); > >However, as my project expands, I find I am trying to pass an hInst which >the system has cunningly initialised to > > 0xcccccccc; **** And why would this be surprising. In debug mode, it is *supposed* to initialize local variables to 0xcccccccc just to catch the kind of serious error you committed. This is a bug in your code, and you need to fix it. You are using an uninitialized local variable! If this *ever* worked, it was at best a wild accident. What you did NOT show, and is utterly essential to understanding the problem, is where and how the variable is declared! joe **** > >And it is happening in some very inconvenient call-backs. And it is >screwing things up big time! > >So I need to set the resource handle only if it is valid. Is there a >function which tells one whether an HINSTANCE is a valid module? Something >like what IsWindow() does for Window handles? > >I could try >::GetModuleFileName( .... ); > >but I don't want the name, just to know that it is a proper module. > >Dave Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on 2 Jun 2010 20:06 See below... On Wed, 2 Jun 2010 17:54:29 +0100, "David Webber" <dave(a)musical-dot-demon-dot-co.uk> wrote: >I haven't checked it rigorously, but I'm getting the impression that >AfxSetResourceHandle() used to be tolerant of getting a NULL HINSTANCE up >to VS2008 and no longer is in 2010. > >It certainly has > > ASSERT(hInstResource != NULL); **** This seems like a Really Good Idea. In fact, passing a NULL handle sounds like a program bug. Exactly why is it that a program is supposed to run and give a simulation of producing something if it contains a deep and serious bug like a NULL HINSTANCE? So if your program had a NULL HINSTANCE, it was erroneous, and you have finally discovered that fact. **** > >now. > >For a while I got things working by replacing my > AfxSetResourceHandle( hInst ) >by > if( hInst ) AfxSetResourceHandle( hInst ); > >However, as my project expands, I find I am trying to pass an hInst which >the system has cunningly initialised to > > 0xcccccccc; > >And it is happening in some very inconvenient call-backs. And it is >screwing things up big time! **** I already explained this. But what amazes me is that people ask a question and omit ALL of the essential information required to answer that question, such as where variables are declared, where they are initialized, in what context the error occurs, the traceback, and a few other utterly critical piece of information without which the question becomes, simply, "My program doesn't work, Can you tell me what I did wrong?" This is one of those questions, except that at least part of the answer is glaringly obvious: you have an uninitialized local variable somewhere in the chain of logic that leads to the problem described. joe **** > >So I need to set the resource handle only if it is valid. Is there a >function which tells one whether an HINSTANCE is a valid module? Something >like what IsWindow() does for Window handles? > >I could try >::GetModuleFileName( .... ); > >but I don't want the name, just to know that it is a proper module. > >Dave Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
|
Next
|
Last
Pages: 1 2 3 Prev: Heap stack Class questons Next: Format of the What's This Popup Help Text file |