1

次を使用してpython 3.5で呼び出された、4つの関数を持つ.dll名前付きのがあります。my.dll
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 に答える