0

在使用 Python 2.6 和 ctypes 的 Win7 上,我试图在 COM dll 中调用函数但没有成功。
这是我正在做的代码片段。

import ctypes
from ctypes import *
h_func = c_int(0);
h_c    = c_int(0);
h_text = ctypes.create_string_buffer(32);
usbDll = ctypes.WinDLL ("c:\\temp\\PwrUSBDll.dll");
CheckStatusPowerUSB = usbDll.CheckStatusPowerUSB;
InitPowerUSB = usbDll.InitPowerUSB;
#
#===This is where it all goes down the tubes.
#
InitPowerUSB (byref(h_func), byref(h_text), byref(h_c));
#
# I keep getting a WindowsError: exception: access violation writing 0x00000000
#
print h_func.value;
print h_text.value;
print h_c.value;

InitPowerUSB 接受两个参数来返回数据并返回一个返回码。
谁能帮我这个。我有这个在 C# 中工作没有问题。

4

1 回答 1

1

Why not use pypowerusb?

Looking at the relevant header file, InitPowerUSB takes only one argument, a pointer to integer, while you supply three arguments.

Try calling the function with only a single argument.

于 2012-12-27T21:02:55.140 回答