Reputation: 2081
How can i implement this function using python ctypes
extern int __stdcall GetRate(HANDLE hDev, int* pData)
How to set datatypes so that i can print pData value
Upvotes: 9
Views: 17907
Reputation:
If you want to call a function named GetRate
, you can do it as:
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, function pointer, you can do it as (I think you're looking for the first):
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
Upvotes: 10