1

我有一个.dllnamed 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)

我在其他地方看过这里:

  1. python-ctypes-prototype-with-lpcstr-out-parameter

  2. 在 DLL 函数调用中使用字符串参数

将 200 个空格的字符串传递给 dll 的正确方法是什么?

先感谢您

4

1 回答 1

1

您指出原型是:

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')
于 2016-04-22T02:07:47.400 回答