c++ - 调用 dll 函数时出现“运行时检查失败 #0 - ESP 的值”
问题描述
我有一个带有 lib.h 的 dll:
#pragma once
#ifdef EXPORTS
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport)
#endif
extern "C" API void test1(std::vector<ValueType*>* functions);
和 lib.cpp:
#include "pch.h"
#include <iostream>
#include <vector>
#include "ValueType.h"
#include "NumberValue.h"
#include "TestLib.h"
void test1(std::vector<ValueType*>* functions) {
functions->push_back(new NumberValue(123321));
使用此 dll 的主文件是:
#include <iostream>
#include <vector>
#include <Windows.h>
#include "ValueType.h"
using namespace std;
typedef void (WINAPI* importedInitFunction)(std::vector<ValueType*>*);
importedInitFunction test1F;
std::vector<ValueType*> values;
int main() {
while (1) {
HMODULE lib = LoadLibrary("DllTest1.dll");
test1F = (importedInitFunction)GetProcAddress(lib, "test1");
test1F(&values);
test1F(&values);
std::cout << values.at(0)->asString();
FreeLibrary(lib);
system("pause");
}
return 0;
}
当我试图编译我的代码时,我发现错误说:“运行时检查失败 #0 - ESP 的值没有在函数调用中正确保存。”,在“test1F(&values);”行。
如何解决?
解决方案
推荐阅读
- html - 使用绝对定位将 div 类居中
- unity3d - 使用 Unity Visual Scripting(在编辑器中工作)时,无法在移动构建中从我的可脚本化对象加载变量
- sql - Laravel group by & sum 查询
- asp.net-core - 在 .net 核心中使用 excel 文件的种子数据
- javascript - 使用 Yup 验证具有最小/最大范围的可空字符串
- python - tkinter 按钮仅在单词在文本框 python 中时可见
- json - 如何在自适应卡片模板中使用 $when 来找出传入数据有效负载的长度并删除输入块
- python - 如何停在函数外的一行
- java - 为什么使用“multipart/form-data”上传文件时经常出现异常?
- docker - docker 卷与挂载点 docker 卷有什么区别