Python ctypes调用简单的c++dll
Python ctypes calling simple c++ dll
我真的很难用ctypes 从python调用一个简单的c++dll
下面是我的C++代码:
#ifdef __cplusplus
extern "C"{
#endif
__declspec(dllexport) char const* greet()
{
return "hello, world";
}
#ifdef __cplusplus
}
#endif
我的Python代码:
import ctypes
testlib = ctypes.CDLL("CpLib.dll");
print testlib.greet();
当我运行py脚本时,我得到了-97902232
的奇怪返回值
请协助。
您没有告诉ctypes返回值的类型,因此它假设它是一个整数。但它实际上是一个指针。设置restype属性,让ctypes知道如何解释返回值。
import ctypes
testlib = ctypes.CDLL("CpLib.dll")
testlib.greet.restype = ctypes.c_char_p
print testlib.greet()
相关文章:
- 在Visual Studio 2017中创建的简单DLL不会在XP中加载
- 使用mingw遵循简单的c ++ DLL教程时出错
- 使用自定义简单 Mapi DLL,无需安装 Outlook
- 使用 VS2010 MFC + 测试应用的简单 DLL
- 如何从C++DLL中的C#简单函数调用
- 使用pinvoke调用的简单C++.dll;对我有效,但对其他人无效
- 在DLL中使用的最简单的C++PUSH通知/POST解决方案
- 程序无法启动,因为您的计算机中缺少libgcc_s_dw2-1.dll。简单的控制台
- 这个简单的C++ DLL 在 C# 中不起作用
- dll注入:使用opengl绘制简单的游戏覆盖图
- Python ctypes调用简单的c++dll
- 如何在c#代码中修改c++ dll中定义的简单类型变量
- 无法链接简单的DLL解决方案
- 如何加载加载win32 dll和执行简单的winapi与firebreath
- 简单的JPG库(dll),仅用于保存JPG图像
- UAC提升使用简单的COM dll
- 创建自定义简单Mapi DLL,执行时失败
- 使用cmake构建Windows DLL的简单示例
- 使用Winsock DLL在简单的TCP回显服务器中分离消息
- 需要简单的演示调用Delphi DLL在c++中