gpt4 book ai didi

c# - p/invoke 不平衡堆栈错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:51:00 25 4
gpt4 key购买 nike

我有以下 C++ 函数和 C# p/invoke decleration:

//C#
[DllImport("capture.dll", EntryPoint = "setup")]
public static extern void captureSetup(int rr);

//C++
extern "C" {
__declspec(dllexport) void setup(int rr)

但我收到有关 p/invoke 不平衡堆栈的错误,这可能是由托管签名与非托管签名不匹配引起的。

谁能看出这有什么问题?

最佳答案

这是调用约定不匹配。 C++ 代码默认使用 cdecl,但 C# 假定使用 stdcall。您需要使它们匹配,例如

[DllImport("capture.dll", EntryPoint = "setup", 
CallingConvention = CallingConvention.Cdecl)]
public static extern void captureSetup(int rr);

关于c# - p/invoke 不平衡堆栈错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8348316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com