我正在尝试在 VS2015 中构建一个 dll 项目以将其部署到 Windows XP 上。它适用于 Windows 7,但在 Windows XP SP3 上出错:
The procedure entry point InitializecriticalSectionEx could not be located in the dynaic link libray KERNEL32.dll
我已经构建了库:
Configuration=Release;Platform=x86;PlatformToolset=v140_xp;
不幸的是,InitializeCriticalSectionEx
XP 版本的 Kernel32.dll 中不存在此功能,即使安装了 SP3。它直到 Vista 才被引入。您使用的驱动程序似乎与 XP 不完全兼容。
是否可以在不降级构建 PlatformToolset 的情况下解决此问题?
最佳答案
由于您需要 DLL 在 InitializeCriticalSectionEx()
不可用的操作系统上运行,因此您无法在编译时静态链接到该函数。这就是您收到入口点错误的原因。
相反,您必须在运行时使用 GetProcAddress()
动态加载 InitializeCriticalSectionEx()
函数(或内部使用 GetProcAddress()
的 linker's delay-load feature)。
如果 InitializeCriticalSectionEx()
函数在运行时加载失败,您的代码可以回退到其他内容,例如 InitializeCriticalSection()
甚至 InitializeCriticalSectionAndSpinCount()
.
关于c++ - InitializeCriticalSectionEx 不在 KERNEL32.Dll 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52791834/