我正在尝试在资源文件.rc 中实现一个字符串表,然后使用函数 CString::LoadStringW() 加载特定的字符串。这是代码 main.cpp:
#ifndef _AFXDLL
#define _AFXDLL
#endif
#include <afx.h>
#include <stdio.h>
#include "resource.h"
int main()
{
printf("Code Example: Load resource file data\n");
CString sentence;
sentence.LoadStringW(IDS_STRING101);
printf("Sentence: %s", sentence);
getchar();
return 0;
}
已经有很好的链接描述,如何使用资源文件:
http://www.cplusplus.com/forum/windows/119338/
http://www.winprog.org/tutorial/resources.html
问题是当我编译代码然后尝试运行时,它不会读取字符串。调试时,带有 LoadStringW() 函数的行会抛出断言错误:
Debug Assertion Failed!
Program: C:\WINDOWS\SYSTEM32\mfc140ud.dll
File: f:\dd\vctools\vc7libs\ship\atlmfc\include\afxwin1.inl
Line: 24
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
在我提供的第一个 URL 的末尾(作为最后一步)链接已编译的资源文件 .rc 和我的源文件 main.cpp。我不确定如何执行此操作,也许这就是我的程序无法按预期工作的原因。
请问,你有什么建议吗?
我正在尝试 MSVS 2015 / 2017。
谢谢。