开发者

Reference Parameters in Python

I am using 开发者_运维百科a custom SDK for a WWAN card. I want to be able to access the functions from the dll in python. I have read up on loading the dll and accessing the functions.

The part I am stuck on is using the functions that have reference parameters and arrays and using them in python.

Here is the documentation page for a function I need help with:\ http://i.imgur.com/0W20Q.png

I put the dll into system32 so I can access it without a direct path.

So far I have:

from ctypes import *
sdk = windll.GobiConnectionMgmt
sdk.QCWWAN2kEnumerateDevice( )

I am unsure how to format the parameters and return type. Any help would be awesome.


Well, I think pDevicesSize should be integer, and pDevices should be a list of objects whose class have deviceId(str) and deviceKey(str) as properties.


Declaring a structure in the proper device format and passing that will make it easier to process the devices when they are returned. Here's an example:

from ctypes import *

class Device(Structure):
    _fields_ = [
        ('id',c_ubyte * 256),
        ('key',c_ubyte * 16)]

sdk = windll.GobiConnectionMgmt
enumerate_device = sdk.QCWWAN2kEnumerateDevices
enumerate_device.restype = c_ulong
enumerate_device.argtypes = [POINTER(c_ubyte),POINTER(Device)]

max_devices = 3
# create a c_ubyte object that can be passed by reference to get the out value.
c = c_ubyte(max_devices)
# create an array of devices
s = (Device * max_devices)()
enumerate_device(byref(c),s)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜