[英]WinAPI C++ how to load resources from 64-bit application
I want to load out resources from an EXE.我想从 EXE 加载资源。 For example I want to load version info
RT_VERSION
, from EXE path
例如,我想从 EXE
path
加载版本信息RT_VERSION
Normally I would do this way通常我会这样做
HMODULE lib = LoadLibrary(path);
HRSRC resVersion = FindResource(lib, MAKEINTRESOURCE(1), RT_VERSION);
DWORD resVersionSize = SizeofResource(lib, resVersion);
HGLOBAL resVersionLoad = LoadResource(lib, resVersion);
LPVOID resVersionData = LockResource(lib);
But when the exe of path
is a win-64 application, LoadLibrary
fails with ERROR_BAD_EXE_FORMAT : %1 is not a valid Win32 application.
但是当
path
的 exe 是一个 win-64 应用程序时, LoadLibrary
失败并显示ERROR_BAD_EXE_FORMAT : %1 is not a valid Win32 application.
Is there anyway to load resources from win-64 application?无论如何从win-64应用程序加载资源?
Windows only allows you to load modules of the same bitness into a process. Windows 只允许您将相同位数的模块加载到进程中。 When you are calling
LoadLibrary
, the system assumes that you will be using that module, and does the usual initialization.当您调用
LoadLibrary
,系统假定您将使用该模块,并执行通常的初始化。 To prevent that you need to call LoadLibraryEx instead, passing the LOAD_LIBRARY_AS_IMAGE_RESOURCE
flag:为了防止您需要调用LoadLibraryEx ,传递
LOAD_LIBRARY_AS_IMAGE_RESOURCE
标志:
If this value is used, the system maps the file into the process's virtual address space as an image file.
如果使用此值,系统会将文件作为映像文件映射到进程的虚拟地址空间。 However, the loader does not load the static imports or perform the other usual initialization steps.
但是,加载器不会加载静态导入或执行其他常见的初始化步骤。 Use this flag when you want to load a DLL only to extract messages or resources from it.
当您只想加载 DLL 以从中提取消息或资源时使用此标志。
Unless the application depends on the file having the in-memory layout of an image, this value should be used with either
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE
orLOAD_LIBRARY_AS_DATAFILE
.除非应用程序依赖于具有图像内存布局的文件,否则该值应该与
LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE
或LOAD_LIBRARY_AS_DATAFILE
。 For more information, see the Remarks section.有关更多信息,请参阅备注部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.