Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading a string resource.

Posted on 1998-12-05
9
Medium Priority
?
586 Views
Last Modified: 2008-02-26
I am having a real problem loading a string reasource. I started with CString::LoadString(id), but kept getting an assertion failure at the same place the the Bitmap problem below occurs. I changed to using LoadString(HINSTANCE, ... char*, etc), and that worked.

I then meved on and created an about Dialog box. I put a bitmap in and assigned it to a bitmap id in the resource file. But I get the same assertion error as previosly...

AfxGetResourceHandle() line 22 + 33 bytes
CDialog::DoModal() line 496 + 5 bytes
About::DoModal() line 47 + 8 bytes
WindowProc(HWND__ * 0x00000868, unsigned int 273, unsigned int 40001, long 0) line 144
KERNEL32! bff7363b()
KERNEL32! bff942e7()

Do i need to register the HINSTANCE I get passed in my WinMain(), if so, how? if not, what else is wrong?

Thanks.
Nigel
0
Comment
Question by:nigel5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1179272
>>Do i need to register the HINSTANCE I get passed in my WinMain()
No.

It would help if we could see the code where the problems are occuring.
0
 
LVL 3

Expert Comment

by:stefanr
ID: 1179273
It could perhaps be that the LoadString command is called before the application is fully up and running. If that is the case, try to call LoadString later in your code (maybe at the end of InitInstance) and see if that works.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1179274
Why would that matter?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 1179275
>>Do i need to register the HINSTANCE
>>AfxGetResourceHandle() ...
These two statements from your text tell everything - as you're obviously using a MFC' app or a DLL, you'll have to use 'AfxSetResourceHandle ()' supllying the 'HINSTANCE' that was passed to your 'WinMain()'
0
 

Author Comment

by:nigel5
ID: 1179276
I am now able to use LoadString, but I still get the problem with the About Dialo I am trying to load. Not sure what the stack trace means, I have not delved this far into Windows stuff.

AfxGetInstanceHandle() line 19 + 33 bytes
AfxEndDeferRegisterClass(short 16) line 3609 + 5 bytes
CWnd::CreateDlgIndirect(const DLGTEMPLATE * 0x00409c8c, CWnd * 0x00000000 {CWnd hWnd=0xcc000000}, HINSTANCE__ * 0x00400000) line 276 + 32 bytes
CDialog::DoModal() line 525 + 26 bytes
About::DoModal() line 47 + 8 bytes
WindowProc(HWND__ * 0x00000d10, unsigned int 273, unsigned int 40001, long 0) line 150
KERNEL32! bff7363b()
KERNEL32! bff942e7()


The about dialog source is as follows....

// About.h
///////////////////////////////////////
#if !defined(_About_H__)
#define _About_H__

#if _MSC_VER >= 1000
#pragma once
#endif

/////////////////////////////////////////////////////////////////////////////
// About dialog

class About : public CDialog
{
// Construction
public:
      About(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
      //{{AFX_DATA(About)
      enum { IDD = IDD_DIALOG1 };
            // NOTE: the ClassWizard will add data members here
      //}}AFX_DATA


// Overrides
      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(About)
      public:
      virtual int DoModal();
      protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
      //}}AFX_VIRTUAL

// Implementation
protected:

      // Generated message map functions
      //{{AFX_MSG(About)
            // NOTE: the ClassWizard will add member functions here
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()

private:

};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif

//////////////////////////////////////////////
//About.cpp
// About.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "About.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// About dialog


About::About(CWnd* pParent /*=NULL*/)
      : CDialog(About::IDD, pParent)
{
      //{{AFX_DATA_INIT(About)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT
}


void About::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(About)
            // NOTE: the ClassWizard will add DDX and DDV calls here
      //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(About, CDialog)
      //{{AFX_MSG_MAP(About)
            // NOTE: the ClassWizard will add message map macros here
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// About message handlers

int About::DoModal()
{
      int ret = CDialog::DoModal();
      return ret;
}

/////////////////////////////////////

Basically I yanked this from another app that I created with the AppWizard.
0
 

Author Comment

by:nigel5
ID: 1179277
I use code to create and use this window...
in winmain

on an IDM_ABOUT message
About a;
a.DoModal();

Funnily enough, if I ignore the assertation failure, the dialog appears with the correct bitmap, but I get an unhandled exception in MFC42D.DLL, 0xC00000005 unhandled exception.

Now, I'm really confused.

0
 

Author Comment

by:nigel5
ID: 1179278
The exception happens at line 3532 of wincore.cpp

if (!AfxGetThread()->PumpMessage())

???????????
0
 
LVL 86

Expert Comment

by:jkr
ID: 1179279
>> CWnd * 0x00000000
This function is being called with an invalid CWnd pointer - it seems that your resource template couldn't be loaded properrly ... give me a moment to take a look at the code ;-)
0
 

Author Comment

by:nigel5
ID: 1179280
It doesn't matter, as I have managed to get round the problem. Thanks though. still an interesting problem :)

Regards.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question