Click here to Skip to main content
15,915,702 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questiondelete operator Pin
iayd16-May-08 4:30
iayd16-May-08 4:30 
AnswerRe: delete operator Pin
toxcct16-May-08 4:34
toxcct16-May-08 4:34 
AnswerRe: delete operator Pin
Cedric Moonen16-May-08 4:39
Cedric Moonen16-May-08 4:39 
AnswerRe: delete operator Pin
jeron116-May-08 4:40
jeron116-May-08 4:40 
AnswerRe: delete operator [modified] Pin
CPallini16-May-08 4:42
mveCPallini16-May-08 4:42 
AnswerRe: delete operator Pin
David Crow16-May-08 5:00
David Crow16-May-08 5:00 
GeneralRe: delete operator Pin
iayd16-May-08 12:41
iayd16-May-08 12:41 
QuestionDebug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
panzerdivisionmarkus16-May-08 4:01
panzerdivisionmarkus16-May-08 4:01 
Hi,

I have a wierd problem that I hope someone here can help me out with. And if I posted in the wrong forum please redirect me.

Anyway, I have a program where I load a Dll, which then loads a bunch of other dlls. I recently did some changes so that the program would support unicode. After the changes I got these wierd problems:

One of the dlls causes a debug assertion failed when loading from it's resource, and another doesn't. They both use the following code:
HRESULT CPictureWnd::LoadResource(WORD wId, LANGID wLangId) { 
    LPCTSTR sTemplateName = MAKEINTRESOURCE(wId); 
    HINSTANCE hInst = AfxFindResourceHandle(sTemplateName, _T("GIF_IMAGE")); 

    HRSRC hResInfo = ::FindResourceEx(hInst, _T("GIF_IMAGE"), sTemplateName, wLangId); 
    if (!hResInfo) hResInfo = ::FindResourceEx(hInst, _T("GIF_IMAGE"), sTemplateName, 0x409); 

   ...(other code)
    return hr; 
} 


The Dll that manages to call the function uses this code:
CTM_MODULE_API BOOL module_mtype_init(LPMODULE_MTYPE_DATA mtype) 
{ 
  AFX_MANAGE_STATE(AfxGetStaticModuleState()); 
  mtype->pUserData = (_MODULE_MTYPE_USER_DATA*)calloc(sizeof(_MODULE_MTYPE_USER_DATA),1); 
  mtype->pUserData->m_picIcon = new CPictureWnd; 
  mtype->pUserData->m_picIcon->LoadResource(IDB_PATHICON,mtype->langId); 
  return TRUE; 
} 


And the one who gets the assertion uses this:

CTM_MODULE_API BOOL module_mtype_init(LPMODULE_MTYPE_DATA mtype) 
{ 
  AFX_MANAGE_STATE(AfxGetStaticModuleState()); 
  mtype->pUserData = (_MODULE_MTYPE_USER_DATA*)calloc(sizeof(_MODULE_MTYPE_USER_DATA),1); 
  mtype->pUserData->m_picIcon = new CPictureWnd; 
  mtype->pUserData->m_picIcon->LoadResource(IDB_PATHICON,mtype->langId); 
  return TRUE; 
} 



I get the debug assertion failes at the following row:
HINSTANCE hInst = AfxFindResourceHandle(sTemplateName, _T("GIF_IMAGE"));



I also get an assertion failure in my dll which loads the other dlls in the following code:

Cctm::Cctm(void)
:m_lock("Cctm::lock")
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState());

  m_initialized=FALSE;
  ...other code

  //path to the DLL

  CString sFile;
  GetModuleFileName(AfxGetResourceHandle(), sFile.GetBuffer(_MAX_PATH + 1), _MAX_PATH);  

   ...other code
}


The last row causes an assertion. If I comment out AFX_MANAGE_STATE(AfxGetStaticModuleState()); things seems to work better, but then it fetches texts from the wrong resource files and I got some wierd krasch.



All this worked before I switched to Unicode. Anyone have any idea of whats going on? I really need to get this stuff to work and I don't understand why it doesn't.



Environment: VS 2003, C++, XP Pro, MFC in shared dll to the program and all the dlls.
AnswerRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
Gary R. Wheeler17-May-08 1:09
Gary R. Wheeler17-May-08 1:09 
GeneralRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
panzerdivisionmarkus18-May-08 21:35
panzerdivisionmarkus18-May-08 21:35 
GeneralRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
Gary R. Wheeler19-May-08 0:12
Gary R. Wheeler19-May-08 0:12 
GeneralRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
panzerdivisionmarkus19-May-08 23:30
panzerdivisionmarkus19-May-08 23:30 
GeneralRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
Gary R. Wheeler20-May-08 0:07
Gary R. Wheeler20-May-08 0:07 
GeneralRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
panzerdivisionmarkus20-May-08 0:57
panzerdivisionmarkus20-May-08 0:57 
GeneralRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
panzerdivisionmarkus20-May-08 1:14
panzerdivisionmarkus20-May-08 1:14 
GeneralRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
Gary R. Wheeler20-May-08 11:44
Gary R. Wheeler20-May-08 11:44 
AnswerRe: Debug assertion when using AFX_MANAGE_STATE(AfxGetStaticModuleState()) Pin
panzerdivisionmarkus21-May-08 23:03
panzerdivisionmarkus21-May-08 23:03 
Questionproblem in migrating from VC6 to VC2005 Pin
ptr_Electron16-May-08 3:54
ptr_Electron16-May-08 3:54 
AnswerRe: problem in migrating from VC6 to VC2005 Pin
led mike16-May-08 4:17
led mike16-May-08 4:17 
Questionradiobuttons,vc++ Pin
Mohanraj D16-May-08 3:48
Mohanraj D16-May-08 3:48 
AnswerRe: radiobuttons,vc++ Pin
CPallini16-May-08 3:54
mveCPallini16-May-08 3:54 
AnswerRe: radiobuttons,vc++ Pin
toxcct16-May-08 4:03
toxcct16-May-08 4:03 
AnswerRe: radiobuttons,vc++ Pin
David Crow16-May-08 4:58
David Crow16-May-08 4:58 
GeneralRe: radiobuttons,vc++ Pin
Hamid_RT16-May-08 7:32
Hamid_RT16-May-08 7:32 
GeneralRe: radiobuttons,vc++ Pin
David Crow16-May-08 7:56
David Crow16-May-08 7:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.