C dll由于对未调用的不存在的函数的引用而未加载
C++ DLL not loading because of a reference to a non-existent function that is not called
在dll i有以下代码,该代码有条件地调用Windows 8函数IsimmermerSiveProcess()。由于此功能不存在,因此DLL不会在Windows 7上加载。因为实际上没有调用此功能,所以我该怎么做才能强制DLL加载到内存?
#include <Windows.h>
#include <VersionHelpers.h>
...
if ( IsWindows8OrGreater() )
IsImmersive = IsImmersiveProcess ( GetCurrentProcess() );
加载此dll时我从c#遇到的错误是:
Unable to load DLL 'd.dll': The specified procedure could not be found. (Exception from HRESULT: 0x8007007F)
-
-
谢谢大家。我根据答案的最终代码如下:
BOOL (WINAPI *pIsImmersiveProcess) ( HANDLE hProcess );
byte IsImmersive = 0;
pIsImmersiveProcess = (BOOL (WINAPI *) ( HANDLE hProcess ))
GetProcAddress ( GetModuleHandle ( L"User32.dll" ), "IsImmersiveProcess" );
if ( pIsImmersiveProcess )
IsImmersive = pIsImmersiveProcess ( GetCurrentProcess() );
就编译器和链接器而言,该函数被称为。
有两种避免这种方法:
-
在编译时间中排除呼叫,以使编译器知道它没有调用。
-
避免对该功能的编译时间引用并在运行时获得其地址。
对于第一种方法,您可以根据编译时间已知Windows版本进行专门设计模板。
但是,如果您想要所有受支持的Windows版本的单个DLL,则需要使用第二种方法,本质上是使用GetProcAddress
。
相关文章:
- g++ 说函数不存在,即使包含正确的标头
- C++ 尝试在不存在的构造函数中引用已删除的函数(使用 rapidJson)
- C++,QT. QShortcut的函数调用不存在
- C++不存在合适的转换函数
- 编译器错过了无效的构造函数调用,并调用不存在的(或私有的)默认构造函数
- 调用成员函数,尽管该对象不存在
- 函数 NetShareGetInfo 始终返回 2310(此共享不存在)
- 当不存在这样的构造函数时,将类传递给构造函数.它为什么起作用
- 如果派生类还具有基类中不存在的虚函数,则创建的 vptr 数
- 在C++中传递结构数组 - 被调用函数中不存在结构元素,如何正确传递向量?
- C 类不存在默认的构造函数
- 从返回函数中推断不存在的模板参数
- 打开不存在的文件时如何使流构造函数失败?
- C++:你如何确定一个解是微不足道的还是不存在的二次函数?
- 如何在C++中调用不存在的函数
- 错误:类不存在默认构造函数
- 在不存在的对象上调用静态成员函数
- 子 - c++ 不存在默认构造函数
- 当函数不存在时,SFINAE 回退
- C++ 错误:不存在从 "math::Vec3<float>" 到 "float" 的合适转换函数