'dll_file'可以是"0":这不符合函数的规范'GetProcAddress'
'dll_file' could be '0': This does not adhere to the specification for the function 'GetProcAddress'
所以我想使用我创建的DLL,我有一个非常奇怪的警告,我没有看到有人有这个。我检查了LoadLibray
是否返回"NULL",但事实并非如此。
typedef DATA_BLOB(*encryption_decryption)(DATA_BLOB, bool*);
HINSTANCE dll_file = LoadLibrary(L"dllForEncryptionNDecryptionn.dll");
if (dll_file != NULL) {
cout << "Library loaded!" << endl;
}
else {
failed();
}
encryption_decryption encryption = (encryption_decryption)GetProcAddress(dll_file,"encryption");
if(encryption != NULL)
{
cout << "Workded!" << endl;
}
else
{
failed();
}
void failed() {
cout << GetLastError() << endl;
cout << "Faild!" << endl;
}
第 8 行的警告:"'dll_file'可能是'0':这不符合函数'GetProcAddress'的规范。
一切正常,当我运行它时它不会写入任何错误。
如果LoadLibrary
出现任何问题,请调用打印错误代码并返回的failed()
。
HINSTANCE dll_file = LoadLibrary(L"dllForEncryptionNDecryptionn.dll");
if (dll_file != NULL) {
cout << "Library loaded!" << endl;
}
else {
failed(); // returns even when dll_file is NULL
}
// so, here you don't know if it's NULL or a valid handle which is why you get the warning
encryption_decryption encryption = (encryption_decryption)GetProcAddress(dll_file,"encryption");
如果LoadLibrary
失败,则不应使用该dll_file
调用GetProcAddress
。
encryption_decryption encryption = nullptr;
HINSTANCE dll_file = LoadLibrary(L"dllForEncryptionNDecryptionn.dll");
if(dll_file) {
encryption_decryption encryption =
(encryption_decryption)GetProcAddress(dll_file,"encryption");
} else {
// do NOT call GetProcAddress
}
if(encryption) {
// function successfully loaded
}
相关文章:
- 递归模板化函数不能分配给具有常量限定类型"const tt &"的变量"state"
- 为什么虚函数不能是静态的和全局的?
- g++ 说函数不存在,即使包含正确的标头
- 当调用switch语句中的函数时(即使函数不包含循环),似乎是永不结束的循环的问题
- C++Brute Force攻击函数不会返回结果
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- 为什么我的数组双精度函数不起作用?
- std::unordered_map析构函数不释放内存?
- 函数不接受 X 参数,函数使用默认参数
- 为什么用户定义的函数不按照给定的顺序对相同长度的元素进行排序?
- 函数签名与调用的函数不匹配,常量字符[]和字符*之间的区别?
- 从函数(不抛出函数)返回异常以进行消息格式化?
- 如何修复加载图标()函数不显示图标?
- 被覆盖的函数不会反映在基类中,这是正常行为吗?
- 为什么这个噪声函数不处理否定参数?
- C++ - 空模板类构造函数不初始化值
- 为什么在指向对象的迭代器上调用函数不允许我更改对象本身?
- 为什么此模板函数的行为不符合预期?
- 为什么函数乐趣不符合 ADL 的条件
- C++引用和返回的函数调用不符合预期。