简体   繁体   English

WinAPI C++ 如何从 64 位应用程序加载资源

[英]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 or LOAD_LIBRARY_AS_DATAFILE .除非应用程序依赖于具有图像内存布局的文件,否则该值应该与LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVELOAD_LIBRARY_AS_DATAFILE For more information, see the Remarks section.有关更多信息,请参阅备注部分。

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

相关问题 如何使用P / Invoke从64位C#应用程序中调用64位C ++ DLL? - How can I use P/Invoke to call a 64-bit C++ DLL from a 64-bit C# Application? "如何从 32 位 C++ 应用程序启动 64 位 Java 应用程序?" - How to start 64-bit Java application from 32-bit C++ application? 从c / c ++应用程序确定32位操作系统还是64位操作系统 - determine 32-bit OS or 64-bit OS from c/c++ application 在Linux环境下构建32位和64位应用程序(C ++) - Linux environment to build 32 and 64-bit application (C++) 如何在64位机器上将C ++程序编译为64位? - How to compile a C++ program as 64-bit on 64-bit machine? 如何在C ++ Builder XE7 64位应用程序中使用`.CHM`文件? - How may I use `.CHM` files with a C++ Builder XE7 64-bit application? 如何使用Visual C ++ 2010 Express编译64位应用程序? - How to compile a 64-bit application using Visual C++ 2010 Express? 从 ASM(64 位汇编)C++ 中获取价值 - Get Value From ASM (Assembly 64-bit) C++ 是否可以从为64位代码运行的“任何CPU”编译的.NET应用程序中调用64位本机C ++ DLL文件? - Is it possible to call 64-bit native C++ DLL files from a .NET application compiled for 'Any CPU' running as 64-bit code? 如何在C ++中表示64位整数文字? - How should a 64-bit integer literal be represented in C++?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM