[英]How to get data in resource file?
I get the NULL(hRsrc) when it is running.我在运行时得到 NULL(hRsrc)。
.cpp .cpp
HINSTANCE hInstance = AfxGetInstanceHandle();
HRSRC hRsrc = FindResource(hInstance, MAKEINTRESOURCE(IDR_EXE1), _T("EXE"));
if (hRsrc == NULL) {
MessageBox(NULL, TEXT("LoadEmbedded"), TEXT("1"), MB_OK);
}
HANDLE hRes = LoadResource(hInstance, hRsrc);
if (hRes == NULL) {
MessageBox(NULL, TEXT("LoadEmbedded"), TEXT("2"), MB_OK);
}
LPSTR lpRes = (LPSTR)LockResource(hRes);
if (lpRes == NULL) {
MessageBox(NULL, TEXT("LoadEmbedded"), TEXT("3"), MB_OK);
}
.rc .rc
IDR_EXE1 EXE "crashpad_handler.exe"
I set the data id and type.我设置数据ID和类型。
resource.h资源.h
#define IDR_EXE1 105
Does the .rc
file have an #include "resource.h"
statement? .rc
文件是否有#include "resource.h"
语句?
If not, then the IDR_EXE1
macro won't be defined when the .rc
is compiled, and thus the resource's ID will be the literal string "IDR_EXE1"
and not the numeric 105
(use a resource viewer tool to verify that).如果不是,则在编译
.rc
时不会定义IDR_EXE1
宏,因此资源的 ID 将是文字字符串"IDR_EXE1"
而不是数字105
(使用资源查看器工具来验证)。 In which case, you would have to use _T("IDR_EXE1")
instead of MAKEINTRESOURCE(IDR_EXE1)
when calling FindResource()
:在这种情况下,您必须在调用
FindResource()
时使用_T("IDR_EXE1")
而不是MAKEINTRESOURCE(IDR_EXE1)
) :
HRSRC hRsrc = FindResource(hInstance, _T("IDR_EXE1"), _T("EXE"));
Otherwise, fix the .rc
file:否则,修复
.rc
文件:
#include "resource.h" // <-- add this!
IDR_EXE1 EXE "crashpad_handler.exe"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.