尝试复制数组时从 DLL 调用函数时程序崩溃
Program crashes when calling function from DLL when trying to copy an array
今天我尝试制作我的第一个DLL和我的第一个使用DLL的应用程序。
DLL 是用 C++ 制作的,这是我调用的代码:
void Graph::findPath_r(Node* pStart, Node* pEnd, std::vector<cell> &road, cell &costMx)
{
//.....
if(pEnd->getParent() != NULL)
{
while(!path.empty())
{
road.push_back(path.top()->getName());
costMx += path.top()->getGCost();
path.pop();
}
return;
}
return;
}
vector <int>tbcway;
int FUNCTION CalculatePath(int Start, int End, int * Array, int &cost)
{
dgraph->findPath_r(xNode[Start].NodeID ,xNode[End].NodeID,tbcway,cost);
dgraph->reset();
std::copy(tbcway.begin(), tbcway.end(), Array);
tbcway.clear();
return 1;
}
这就是我在 VB.net 中宣布并称之为:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("RCP.dll")> _
Public Shared Function LOAD_SYSTEM() As Boolean
End Function
<DllImport("RCP.dll")> _
Public Shared Function GetPluginVersion() As Integer
End Function
<DllImport("RCP.dll")> _
Public Shared Function CalculatePath(ByVal StartNode As Integer, ByVal EndNode As Integer, ByRef Array() As Array, ByRef cost As Integer) As Integer
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LOAD_SYSTEM()
MsgBox(GetPluginVersion().ToString())
Dim path(4096) As Array
Dim movecost As Integer
CalculatePath(1702, 27932, path, movecost)
End Sub
End Class
那么,这段代码有什么问题呢?我得到的错误是:
调用 PInvoke 函数 'RCP GUI!RCP_GUI。Form1::CalculatePath' 使堆栈不平衡。这可能是因为托管 PInvoke 签名与非托管目标签名不匹配。检查 PInvoke 签名的调用约定和参数是否与目标非托管签名匹配。
这可能是调用约定不匹配。
尝试使用不同的调用约定装饰您的 DllImport,看看哪些有效(我的猜测是它应该是 cdecl)。
相关文章:
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 在C应用程序中运行C++(带有STL)函数
- 如何在c++程序中找到函数的地址
- 如何在信号处理程序和普通函数中对全局变量进行互斥读写操作
- WIN32:C++,为什么在WM_CLOSE上调用Messagebox函数程序正在冻结
- 具有外部"c"和程序集的未定义函数
- 是否可以依赖函数范围的静态变量来执行程序关闭期间调用的方法?
- 程序不会执行函数 c++
- C++调用具有 *this 属性的单个帮助程序函数
- 用于检查值是否为其任何参数的帮助程序函数
- 程序中的布尔函数返回输入的范围无论如何都是无效的
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- 程序不向函数返回值
- C++ 函数程序中的平均输出始终为 0.0
- 使用getline和字符串函数C++程序中的分段错误
- 如何理解哪个递归函数程序需要
- 3 函数加主函数 C 程序计算和显示阶乘
- 在结构中嵌入函数程序集代码
- c++的构造函数和析构函数程序集
- c++基本函数程序编译时不会出现满屏幕的错误