LoadString(AFX_IDP_PARSE_INT) fails in an mfc exe

2019-08-16 22:35发布

AFX_IDP_PARSE_INT is the id for a standard MFC error message (it's defined in afxres.h), but in my project it fails to load, meaning that LoadString returns FALSE, GetLastError returns ERROR_RESOURCE_NAME_NOT_FOUND, and CString stays empty.

This happens even when I try loading it at the beginning of InitInstanse:

BOOL CMyLegacyProject::InitInstance()
{
    CString string;
    if (!string.LoadString(AFX_IDP_PARSE_INT))
            AfxMessageBox(_T("Failed."));
}

This same code works on a new project, however - same linking of MFC (I link to it statically), same WINVER, I've tried making it as similar as my old project, but I can't reproduce the error on a newly started project.

标签: c++ mfc
1条回答
smile是对你的礼貌
2楼-- · 2019-08-16 22:50

It looks like your resources are not building correctly. Make sure your .rc file includes all the AFX resources as well. First I'd try building a brand new project from scratch, test loading the string in that, and then have a look to see what the default .rc file looks like.

It should be including a file called 'afxres.rc', ie your RC should have something like this in it:

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\MyRes.rc2"  // non-Microsoft Visual C++ edited resources
#include "afxres.rc"         // Standard components
#include "afxprint.rc"       // printing/print preview resources
#endif
查看更多
登录 后发表回答