c++ - 从 C 定义的接口编写 C++ DLL
问题描述
我得到了一个 C 头文件,它充当编写 DLL 的接口。然后,可执行文件动态读取该 DLL 以进行测试。我是 DLL 创建世界的新手,我正在努力让可执行文件将我的 DLL 识别为具有它期望的入口点。不幸的是,可执行文件没有告诉我为什么我的 DLL 无效。我曾经使用工具来确保我已经使用正确的名称导出了我的函数,但我猜测我的函数签名签名使它们不兼容。我还确保按照自述文件中的说明构建 x64。
C 接口头文件
#include <stdint.h>
#pragma pack(push, 1)
struct Point
{
int8_t id;
int32_t rank;
float x;
float y;
};
struct Rect
{
float lx;
float ly;
float hx;
float hy;
};
#pragma pack(pop)
struct SearchContext;
typedef SearchContext* (__stdcall* T_create)(const Point* points_begin, const Point* points_end);
typedef int32_t (__stdcall* T_search)(SearchContext* sc, const Rect rect, const int32_t count, Point* out_points);
typedef SearchContext* (__stdcall* T_destroy)(SearchContext* sc);
我的 C++ 头文件
#pragma once
#include <cstdint>
#pragma pack(push, 1)
struct Point
{
int8_t id;
int32_t rank;
float x;
float y;
};
struct Rect
{
float lx;
float ly;
float hx;
float hy;
};
#pragma pack(pop)
struct SearchContext
{
float value;
float minCoverage, maxCoverage;
SearchContext* leftTree;
SearchContext* rightTree;
SearchContext* yTree;
Point* point;
};
extern "C" __declspec(dllexport) SearchContext* create(const Point* points_begin, const Point* points_end);
extern "C" __declspec(dllexport) int32_t search(SearchContext * sc, const Rect rect, const int32_t count, Point * out_points);
extern "C" __declspec(dllexport) SearchContext* destroy(SearchContext * sc);
提前感谢您的帮助!
解决方案
推荐阅读
- typescript - 方法调用的`this`强制
- python - 一个 Python 函数,它需要多少行和多少列,它应该以网格形式打印一对空方括号 []
- python - 即使在 gropandas 绘图时安装了模块 rasterion.io 也找不到
- sql - 当 h2 数据库查询的一部分重复几次时,如何保持它的简短?
- python - “ValueError:无法将权重广播到值。在昏暗 1 处不匹配。” 在序列模型上使用自定义损失函数时
- android - 在android应用程序中显示所有网络响应
- unity3d - 编辑器中的 Unity 模糊和像素化精灵(无像素艺术)
- sql - 对于简单的乘法,Sqlite 更新表的速度真的很慢
- arrays - 从 XML 转换 XSLT 后,在 JSON 中正确表示集合数据
- python - 为什么这个 Plotly 图在 Y 轴和 X 轴上悬停?