Python - 从DLL

时间:2016-10-26 11:12:33

标签: python c++ pointers dll

我在DLL下编译了一个C ++方法

int Method( int Error, char *pMessage, int Position);

而错误和位置是输入,* pMessage是输出

在Python中我使用简单:

mydll = cdll.LoadLibrary("library")
mydll.Method(50,?,20)

对于没有指针的方法,一切都很好。但是我如何从Python中获取C ++指针的值?

1 个答案:

答案 0 :(得分:0)

您可以使用create_string_buffer。我在C ++函数中错过的是字符串的大小,所以我假设它是常量(虽然这可能是一个不好的做法):

from ctypes import create_string_buffer, cdll

N_OF_CHARS = 1024
s = create_string_buffer(N_OF_CHARS)

mydll = cdll.LoadLibrary("library")
mydll.Method(50, s, 20)

print(s.value)