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
Answer from user1129665 on Stack OverflowPython
docs.python.org › 3 › library › ctypes.html
ctypes — A foreign function library for Python
None is passed as a C NULL pointer, ... as pointer to the memory block that contains their data (char* or wchar_t*). Python integers are passed as the platform’s default C int type, their value is masked to fit into the C type. Before we move on calling functions with other parameter types, we have to learn more about ctypes data ...
BestDivision
bestdivision.com › spread your knowledge - bestdivision › questions - bestdivision › python questions - categories - bestdivision › what is the "ctypes.pointer(ctypes.c_int)" type in python? - bestdivision
What is the "ctypes.POINTER(ctypes.c_int)" type in Python? | BestDivision
July 15, 2023 - Usage: Used when interacting with C functions that require pointers to integers as arguments or return values. Definition: ctypes.c_int is a data type that represents a C-style integer (typically 32-bit on most platforms).
Fz-juelich
pgi-jcns.fz-juelich.de › portal › pages › using-c-from-python.html
Using C from Python: How to create a ctypes wrapper - Scientific IT-Systems
This can be done by 'multiplying' the type ctypes.c_int with an integer.
GitHub
github.com › python › cpython › issues › 110777
Add `value` getter to `_ctypes._Pointer` · Issue #110777 · python/cpython
October 12, 2023 - >>> class Foo(ctypes.Structure): >>> _fields_ = [("id", ctypes.c_int)] >>> libfoo.argtypes = (ctypes.c_int,) >>> libfoo.restype = ctypes.POINTER(Foo) >>> a = libfoo.get_foo(1) >>> b = libfoo.get_foo(2) >>> b2 = libfoo.get_foo(2) >>> b3 = ctypes.cast(b, ctypes.POINTER(ctypes.c_int))
Author: python
Tomerfiliba
tomerfiliba.com › recipes › ctype-pointers
ctypes - Pointer from Address - Tomer Filiba
import ctypes def deref(addr, typ): return ctypes.cast(addr, ctypes.POINTER(typ)).contents · # get the ref count of an object (in a very nasty way :) >>> x="hello world" >>> deref(id(x), ctypes.c_int) c_long(1) >>> y=x >>> z=x >>> deref(id(x), ctypes.c_int) c_long(3) ... I’m relying here on id returning the address of an object. This is a weak assumption, but it holds (and is likely to continue to hold) for CPython.
ProgramCreek
programcreek.com › python › example › 1717 › ctypes.pointer
Python Examples of ctypes.pointer
ctypes.c_int() ctypes.POINTER · ctypes.Structure() ctypes.byref() Related Modules · os · sys · re · time · logging · datetime · random · math · subprocess · shutil · threading · struct · json · collections · argparse · The following are 30 code examples of ctypes.pointer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
GeeksforGeeks
geeksforgeeks.org › python › using-pointers-in-python-using-ctypes
Using Pointers in Python using ctypes - GeeksforGeeks
July 23, 2025 - In this we are going to create a pointer value_1 using ctypes module and then printing its type and value. ... import ctypes as ct # value_1 variable stores an integer # of type Ctypes (not a regular integer) value_1 = ct.c_int(10) # printing the type of value_1 print(value_1) # printing the value which value_1 stores print(value_1.value)
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.ctypes.html
numpy.ndarray.ctypes — NumPy v2.2 Manual
... Possessing attributes data, ... omitted undocumented public attributes, as well as documented private attributes): ... A pointer to the memory area of the array as a Python integer....
SageMath
doc.sagemath.org › html › en › thematic_tutorials › numerical_sage › ctypes.html
Ctypes - Thematic Tutorials
Ctypes is a very interesting python package which lets you import shared object libraries into python and call them directly. I should say that even though this is called ctypes, it can be used just as well to call functions from libraries written in fortran. The only complication is you need to know what a fortran function looks like to C. This is simple everything is a pointer, so if your fortran function would be called as foo(A,N) where A is an array and N is its length, then to call it from C it takes a pointer to an array of doubles and a pointer to an int.
SciPy
scipy.github.io › old-wiki › pages › Cookbook › Ctypes.html
Cookbook/Ctypes - SciPy wiki dump
You also don't have to worry about freeing the C data after you're done with it. By allocating your buffers as NumPy arrays, the Python garbage collector can take care of this. ... 1 from ctypes import * 2 ALLOCATOR = CFUNCTYPE(c_long, c_int, POINTER(c_int)) 3 # load your library as lib 4 lib.baz.restype = None 5 lib.baz.argtypes = [c_float, c_int, ALLOCATOR]
Dsheets
dsheets.github.io › codoc › ctypes.0.3.4 › _build › src › ctypes › ctypes
Ctypes
The optional argument format_typ is used by the Ctypes.format_typ and string_of_typ functions to print the type at the top level and elsewhere. If format_typ is not supplied the printer for t is used instead. ... The type of abstract values. The purpose of the abstract type is to represent values whose type varies from platform to platform. For example, the type pthread_t is a pointer on some platforms, an integer ...
GitHub
gist.github.com › nzjrs › 990493
Python ctypes example · GitHub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ... You can define a function which calls malloc() in your shared object and call it through ctypes.
GitHub
github.com › numba › numba › issues › 7399
Allow getting pointer (address) to Numba's int/float variables · Issue #7399 · numba/numba
September 14, 2021 - But didn't find any way of passing a pointer to int64 (np.int64 or numba.int64). Example code: import numba, numpy as np @numba.njit(cache = True) def f(): a = np.zeros((10,), dtype = np.int64) aptr = a[1:3].ctypes b = np.int64 bptr = b.ctypes c = numba.int64 cptr = c.ctypes f()
Author: numba
Terryoy
terryoy.github.io › 2014 › 03 › using-ctypes-to-wrap-c-library.html
Use Ctypes to Wrap C Libraries in Python - Hello, World!
The byref() method create a parameter object of pointer, which you can only use in functions(notice the “cparam” object), while the pointer() method returns a pointer object which you can manipulate later. >>> intc = ctypes.c_int(100) >>> ctypes.byref(intc) # the byref() returns a parameter object that only can be used as a foreign function's parameter(notice a "cparam" object).