gpt4 book ai didi

c++ - 在 C++ 中使 C 函数指针与基于 C 风格堆栈的调用机制一起工作

转载 作者:太空狗 更新时间:2023-10-29 19:38:53 24 4
gpt4 key购买 nike

我想在我的 C++ 程序中从一个 dll 中调用一个纯 C 风格的函数。我尝试使用 reinterpret_cast 将我的函数指针转换为 __cdecl 并且仍然保留了 _stdcall 的调用约定。我是 Windows C++ 编程的新手。

编辑来自评论的代码

reinterpret_cast< Error ( __cdecl*)(int,int)> (GetProcAddress(Mydll::GetInstance()->ReturnDLLInstance(), "add"))(1,10) 

是我的电话。实际的函数语法似乎已声明为

Error __cdecl add(int,int);

调试器向我抛出错误 run time check failure #0。我在 Windows-C++ 中工作

最佳答案

我相信你的问题的解决方案是'extern "C"{ ...'

参见 http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.3

关于c++ - 在 C++ 中使 C 函数指针与基于 C 风格堆栈的调用机制一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6103627/

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