我有一个名为.dll的my.dll,它有4个函数,在python3.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的正确方法是什么?
提前谢谢你
发布于 2016-04-22 02:07:47
你说原型是:
double _stdcall pain_function(double arg1, double arg2, LPSTR arg_string_with_spaces)但使用:
myDLL = ctypes.cdll.LoadLibrary(Path:\to\my.dll)对于__stdcall调用约定,应该是这样的:
myDLL = ctypes.WinDLL('Path:\to\my.dll')https://stackoverflow.com/questions/36778681
复制相似问题