Python integer pointer

How can I implement this function using python types

extern  int __stdcall GetRate(HANDLE hDev, int* pData)

How to set data types so that I can print pData value p>

+4
source share
1 answer

If you want to call a function with a name GetRate, you can do it like:

from ctypes import *
from ctypes.wintypes import *

GetRate = windll.YOURLIB.GetRate
GetRate.restype = c_int
GetRate.argtypes = [HANDLE, POINTER(c_int)]

# now call GetRate as something like:
#
# hDev = ... # handle
# Data = c_int()
#
# GetRate(hDev, byref(Data)) # GetRate(hDev, &Data)
# print Data

but if you try to declare a callback, a pointer to a function, you can do it like (I think you're looking for the first one):

from ctypes import *
from ctypes.wintypes import *

def GetRate(hDev, pDate):
    # Your implementation
    return 0

# you'll need GETRATE to pass it in the argtypes to the target function
GETRATE = WINFUNCTYPE(c_int, HANDLE, POINTER(c_int))
pGetRate = GETRATE(GetRate)

# now you can pass pGetRate as a callback to another function
+6
source

All Articles