当不需要传入任何参数时,它都可以使用相同的dll。但是当我必须传递int或char *时,我会收到错误。我按照Python的ctype文档说明。 C / C ++代码如下,
typedef int LNI;
#if !defined(RC_INCLUDE)
#if !defined(_DLLEXPORT_)
// If _DLLEXPORT_ is not defined then the default is to import.
#if defined(__cplusplus)
#define DLLENTRY extern "C" __declspec(dllimport)
#define STDENTRY extern "C" __declspec(dllimport) HRESULT WINAPI
#define STDENTRY_(type) extern "C" __declspec(dllimport) type WINAPI
#else
#define DLLENTRY __declspec(dllimport)
#define STDENTRY __declspec(dllimport) HRESULT WINAPI
#define STDENTRY_(type) __declspec(dllimport) type WINAPI
#endif
#else // _DLLEXPORT_
// Else if _DLLEXPORT_ is defined then we've been told to export.
#if defined(__cplusplus)
#define DLLENTRY extern "C" __declspec(dllexport)
#define STDENTRY extern "C" __declspec(dllexport) HRESULT WINAPI
#define STDENTRY_(type) extern "C" __declspec(dllexport) type WINAPI
#else
#define DLLENTRY __declspec(dllexport)
#define STDENTRY __declspec(dllexport) HRESULT WINAPI
#define STDENTRY_(type) __declspec(dllexport) type WINAPI
#endif
#endif // _DLLEXPORT_
// Here is the list of service APIs offered by the DLL (using the
// appropriate entry API declaration macros just #defined above).
STDENTRY_(LNI) ldv_open(char* device_name);
我正在尝试使用Python 2.7访问ldv_open,但我继续得到“ValueError:调用过程没有足够的参数< 4字节丢失>或错误的调用约定。我已经解决了这个问题并尝试了我找到的每个解决方案仍然没有解决方案。有人可以告诉我这里我做错了什么吗?
import ctypes
import string
lib = ctypes.CDLL('wldv32')
lib.ldv_open.argtypes = [ctypes.c_char_p]
lib.ldv_open.restype = ctypes.c_int
s = "Lonusb8"
ss = ctypes.c_char_p(s)
print s
print ss
lib.ldv_open(ss)