Вопрос

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

Это было полезно?

Решение

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top