<分区>
平台工具集 - Visual Studio 2017 - Windows XP (v141_xp)
运行时库 - 多线程(无 CRT 依赖项)
DLL 在 Vista+ 上加载正常,但在 XP SP2 (x86) 上失败,错误代码为 ERROR_NOACCESS(对内存位置的访问无效)
动态链接库代码:
#include <windows.h>
#include <string>
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
static std::string test;
break;
}
}
return TRUE;
}
执行代码:
#include <Windows.h>
#include <tchar.h>
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HMODULE hModule = LoadLibrary(L"dll.dll");
if (hModule)
MessageBoxA(0, "It works", "Info", MB_ICONINFORMATION);
else
{
char buff[10];
_itoa_s(GetLastError(), buff, 10, 10);
MessageBoxA(0, buff, "GetLastError()=", MB_ICONEXCLAMATION);
}
return 0;
}
Visual Studio 2015 也有同样的问题。尽管在 Visual Studio 2013 中编译时它工作正常。