我有一个.dll
named my.dll
,有 4 个函数,在 python 3.5 中使用:
myDLL = ctypes.cdll.LoadLibrary(Path:\to\my.dll)
我的问题是调用具有以下功能的函数LPSTR
:
#include "stdafx.h"
#include "newheader.h"
double _stdcall pain_function(double arg1, double arg2, LPSTR arg_string_with_spaces)
其他 3 个电话可以my.dll
正常工作。
下面是我尝试的代码pain_function
:
import ctypes
from ctypes import wintypes
# Load dll
myDLL = ctypes.WinDLL(Path:\to\my.dll)
# Call function
pain_function = myDLL.pain_function
# Typecast the arguments
pain_function.argtypes = [ctypes.c_double, ctypes.c_double, wintypes.LPSTR]
# Typecast the return
pain_function.restype = ctypes.c_double
pain_return = pain_function(arg1, arg2, some_string)
pain_return
返回一些无意义的数字。我尝试了一些变化,主要是:
some_string = ctypes.create_string_buffer(b' ' * 200)
我在其他地方看过这里:
将 200 个空格的字符串传递给 dll 的正确方法是什么?
先感谢您