简体   繁体   English

LoadString(AFX_IDP_PARSE_INT)在mfc exe中失败(不在dll中)

[英]LoadString(AFX_IDP_PARSE_INT) fails in an mfc exe (not in a dll)

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. AFX_IDP_PARSE_INT是标准MFC错误消息的ID(在afxres.h中定义),但在我的项目中无法加载,这意味着LoadString返回FALSEGetLastError返回ERROR_RESOURCE_NAME_NOT_FOUND ,并且CString保持为空。

This happens even when I try loading it at the beginning of InitInstanse: 即使我尝试在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. 相同的代码适用于新项目,但是-相同的MFC链接(我静态链接到它),相同的WINVER,我尝试使其与旧项目相似,但无法在新项目中重现错误开始的项目。

It looks like your resources are not building correctly. 看来您的资源没有正确构建。 Make sure your .rc file includes all the AFX resources as well. 确保您的.rc文件也包括所有AFX资源。 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. 首先,我将尝试从头开始构建一个全新的项目,测试其中的字符串加载,然后看看默认的.rc文件是什么样子。

It should be including a file called 'afxres.rc', ie your RC should have something like this in it: 它应该包括一个名为“ afxres.rc”的文件,即您的RC中应该包含以下内容:

#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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM