Questions tagged [ctypes]
`ctypes` is a Python package that wraps C .dll/.so libraries in pure Python.
4,096
questions
0
votes
0
answers
17
views
How to access Cython struct in Python module?
I have the following Python modules:
temp1.py
import ctypes as c
class datapoints(c.Structure):
_fields_ = [('x', c.c_int16),
('y', c.c_int16),
('z', c.c_int16)]
...
0
votes
1
answer
27
views
Opening explorer and selecting files via SHOpenFolderAndSelectItems with ctypes
In python this can be done with pywin32 like so:
from win32com.shell import shell
def showFilesInExplorer(folder, files):
folder_pidl = shell.SHILCreateFromPath(folder, 0)[0]
files_pidl = [...
0
votes
1
answer
31
views
Setting window properties via SHGetPropertyStoreForWindow using only ctypes
Python developers need to set certain window properties for their applications to work correctly with the Windows taskbar (correct icon and grouping, and the ability to pin). In my case a PyQt5 ...
0
votes
0
answers
35
views
How to kill the explorer.exe file explorer, but not the shell (in Python)
From my research, I found this question, and it had the answer, but it wasn't in Python. The answer to that question was a program called nircmd.exe, which can be used to close "CabinetWClass&...
-2
votes
0
answers
45
views
Using ctypes to access methods from a C++ .NET DLL wrapped with C++/CLI managed code
I am trying to use the ctypes library in Python to access methods from a C++ .NET DLL that has been wrapped using C++/CLI. However, I am encountering an issue and could use some guidance.
The DLL I am ...
0
votes
1
answer
24
views
How to use object identifier from c++ header file in python ctypes
I have a binary file, the structure of which is described by header file. I need to parse file in python.
I have the following header file in C++:
...
#define DWORD unsigned int
...
// What is the ...
0
votes
0
answers
23
views
python ctypes AnimateWindow fails
I'm trying to make tkinter window without default title bar, with icon visible in taskbar and being animated on minimize and de-minimize. The problem is that I encounter return value zero from ...
1
vote
1
answer
31
views
Window procedure overwrite lead to crashes without error when too much instances are created
I'm making an App that uses SDL / Pygame for displaying graphics. I've overwritten the window procedure in case of resizing to trigger a function and makes the app run smoother (cf this answer).
...
0
votes
0
answers
19
views
read a float value from ReadProcessMemory in python
I'm trying to read a float value from memory. Cheat Engine labels the address as "Spider-Man.exe"+6D17018 which is 7FF7F0ED7018 but the ReadBuffer.value is returning 0.0 and the , ...
1
vote
1
answer
34
views
Python program to invert mouse movement when left and right click are simultaneously pressed not working
I am new to python and I was trying to fool around with making a program so that when you are pressing left click and right click it inverts the mouse movement. It runs but it doesnt do anything.
Can ...
0
votes
0
answers
29
views
Access violation with ctypes
I am trying to use a DLL within a python script for a GUI using Tkinter.
I get this error:
write_flag=dfd.newp_usb_send_ascii(ctypes.c_long(deviceID),ctypes.c_char_p(cmd),ctypes.c_ulong(lengt))) ...
0
votes
0
answers
34
views
Passing pointer to ctypes.Structure
I am trying to figure out how to implement a function that waits for an event to be signaled.
The pointer is returned by a dll function which is a struct that stores 3 items. Two of them which are ...
-1
votes
0
answers
41
views
Unpacking C struct_timespec with Python ctypes creates rare wrong values
I have C structure:
typedef struct
{
double cycle_time;
double cycle_duty;
double state;
double servo_mode;
double motion_mode;
double jcond;
struct
{
...
-1
votes
0
answers
35
views
How to figure out ctypes values sizes for python crossplatform app
I have a socket receiver (client/listener/etc), which collects bytes and fill the ctypes structure.
Sender(host) - C language application, which send complicated C structure with nested arrays and ...
1
vote
1
answer
47
views
imported some function from c++ dll to python using ctypes, but some functions doesn't work as expected
so i'm developing a backend using django and i got an image processing step for which i'm using a private c++ .dll developed by my company.
i'm using ctypes to load the .dll file and managed to make ...
1
vote
0
answers
19
views
Enumerating processes using ctypes
Using only the ctypes library, I would like to iterate through Windows processes and obtain the name of each process for comparison checks.
Right now, I am getting weird errors like this:
Failed to ...
0
votes
1
answer
47
views
Showing multiple messages in Python console
If I use ctypes to show message box in python console (without Tkinter), I'm not able to show two boxes at a time. I've to close the first box, then only second box will appear.
What change should I ...
3
votes
1
answer
62
views
Transferring a Pointer From C++ To Python Compatible with Host and Device Memory
I have a Python function (named apply_filter), whose execution may involve either the CPU (using NumPy) and GPU (using CuPy). The function takes an input-buffer object, represting a pointer to data ...
1
vote
1
answer
41
views
ctypes convert Python boolean array to C++ boolean array to pass into function
I have a C++ function that takes in the argument (const BOOL channels[]) and this is the variable that is passed when calling it in C#:
bool[] achannel = new bool[16];
achannel[0] = true;
I'm ...
0
votes
0
answers
54
views
Ctypes LoadLibrary gives FileNotFoundError -- do you have to include header files when loading a C++ DLL in Python with ctypes?
I am attempting to load two C++ DLLs in a Python program using ctypes, however, one of the modules throws an error despite the other loading completely fine. Here is the code:
import ctypes
os....
0
votes
0
answers
28
views
How to handle a precompiled C-library API error in Python? [duplicate]
I am using GMSH, a C-library with a Python API.
Sometimes, GMSH crashes and it forces my Python script to quit. However, I am doing more than one runs in a for loop and if one of them crashes, I would ...
0
votes
0
answers
36
views
ctypes loading binary generates GetProcAddress failed: 0x7f on exit
I wrote a wrapper around a binary file (libmpsse) for use in Windows (there already exists a wrapper around this binary, but only for Linux) while maintaining compatability for an existing wrapper ...
1
vote
0
answers
42
views
Prevent assignment of non-existent field in ctypes Structure
It's relatively easy to shoot yourself in the foot with a typo when assigning a field in a ctypes structure:
structure.fieeld = 10 # Everything works fine except structure.field is unchanged...
Is ...
0
votes
2
answers
46
views
Packaged Python C Extension is missing PyInit_module() in so File
I have created a C library libgac and then wrote Python module implementing bindings with ctype.
I call the python module gazepy.
My project file structure is as follows:
pyproject.toml
setup.py
src
...
1
vote
0
answers
61
views
Python C-Extensions with array of integers argument
I have a simple C++ file that I want to export into Python via a C-extension. I compile my .cc file and create a shared library, which I then call in Python using CDLL from ctypes. However, I am ...
2
votes
1
answer
52
views
Accessing C pointers to vertices in Blender's Python API
I'm currently making a render engine in C and C++ for Blender. I want to access the vertices of a mesh from C via a pointer, to reduce the time spent in Python and avoid unneeded data duplication.
I ...
2
votes
0
answers
38
views
Python3.8 Type-hinting A ctypes function
Solution must support Python3.8
What am I doing wrong?
Is there a simpler way to express what I want (the return value of get_ctypes_func() is a callable, which takes params arg_types and returns ...
1
vote
1
answer
240
views
OSError: exception: access violation reading|writing when calling any function after library instance creation
I'm trying to make use of a SecuGen Fingerprint scanner using Python, the SDK lib I'm using is sgfplib.dll. I have a C++ program that makes use of this DLL and access the hardware using C++ and the ...
0
votes
0
answers
19
views
Perform some task on windows shutdown in python Tkinter app [duplicate]
Imagine you are developing a Python application using Tkinter that performs different tasks on threads.
However, you also want to perform a necessary network call when the window operating system is
...
0
votes
0
answers
45
views
Calling C++ function with ctypes returns different results when compiling with qmake vs. GCC
I am working on a project that requires interfacing a C++ library with Python using ctypes, like in this tutorial (Disclaimer: I know that ctypes is originally meant to be used with C, not C++). I am ...
0
votes
1
answer
43
views
AttributeError: undefined symbol when importing own c compiled function in python
I'm trying to domesticate the numba cfunc compiler ;)
This here is my base_model.py file (the source of my function).
import numpy
import numba
import numba.pycc
cc = numba.pycc.CC('base_model')
cc....
0
votes
0
answers
31
views
Python _Ctypes DLL import error windows 10 [duplicate]
I try to build a Conda environment for my project.
I'm using python 3.12.10.Packages that have been installed using conda command:
Pandas
numpy
tensorflow v2.10
transformers
then I tried to test my ...
0
votes
0
answers
20
views
Opening a system tray program with python
I have a program which when minimized, disappears into the system tray (the sub-process which runs the gui closes and only the parent process is running in the background)
I want to, using python, ...
3
votes
0
answers
29
views
normal Python function, C extension function, ctypes C function, what are the differences?
From my understanding and question:
normal Python function is compiled into byte code, and be executed in a forever loop
C extension function is written in C by user and integrated into interpreter, ...
0
votes
0
answers
43
views
How to convert Ctypes structure with nested structures and arrays to python dict
I have a structure (by Mark Tolonen, great thanks to him!). (I've decided to not rewrite it here, to avoid code duplication with that post). The feature of this structure is that structure may include ...
0
votes
1
answer
65
views
Python and fortran with ctypes: lists with objects
I need to write a library in fortran that will take an array of objects from Python, process it and return it back.
I've tried a lot of options, the last one looks like this:
Code Python:
import ...
1
vote
1
answer
118
views
Could not find .dll module with normal python but works with Anaconda
I am trying to import a .dll in Python using the ctypes package.
import ctypes
example_dll = ctypes.windll.LoadLibrary(".\Example.dll")
This .dll has 2 other .dll dependencies which I have ...
0
votes
1
answer
58
views
Using a C library with Python
I'm writing a Python program under linux to interact with files written in an old format (the 'squishDB' format, where messages from the old Fidonet network were stored in the years from 1980 to 2000)....
0
votes
1
answer
27
views
Python CDLL: Problem with calling libc-Routines in dll
I'm having trouble with calling libc routines from a self compiled dll loaded with ctypes.CDLL.
Here is a minimal example:
DLL is generated in Visual Studio 2022 (OS: Windows 11, everything in 64 bit) ...
0
votes
1
answer
62
views
OverflowError : int too long to convert using ctypes with Win32
I'm trying to change a Window procedure using Win32 API and ctypes.
My code is based to a previous answer that used pywin32 package, with the goal of removing this dependency.
My code raises the ...
0
votes
0
answers
43
views
Tensorflow Could not find the DLL(s) 'msvcp140.dll or msvcp140_1.dll' without explicitly loading them
When I import tensorflow I saw the following errors.
>>> import tensorflow
[WinError 87] 参数错误。
[WinError 87] 参数错误。
Traceback (most recent call last):
File "<stdin>", line 1, ...
1
vote
0
answers
29
views
Compile and load a dll without saving to disk
I'm using dynamic code generation with ctypes, currently to load my compiled code I have to create a DLL on disk:
import pathlib
import subprocess
import ctypes
f = '''
#include <stdio.h>
...
0
votes
1
answer
30
views
Python ctypes TypeError while calling a DLL function
I have a DLL which I load with ctypes CDLL and then I am calling DLL functions via python. Sadly I do not have the original DLL coding, however I have an C header file where the function INPUTS and ...
0
votes
1
answer
27
views
error when compiling c flie with cblas.h, getting error error: expected identifier or ‘(’ before ‘__extension__’
I'm trying to create a shared library for python using ctypes. The following command works fine for my purpose:
gcc -g -fPIC -Wall -Wextra -pedantic *.c -shared -o cfunctions.so
However, when I use #...
0
votes
0
answers
34
views
Faster c_double_array. so close
I have a numpy array that I need to get to a dll function wrapped in ctypes.
myFunc.argtypes = (...POINTER(ctypes.c_double),POINTER(ctypes.c_double),...)
myFunc(...Data1_arr,Data2_arr...)
I'm ...
0
votes
0
answers
73
views
How to use pointer to an array of custom objects in ctypes
I have a ctypes structure defined like this:
class CNode(Structure):
pass
CNode._fields_ = [
("type", c_int32),
("children", POINTER(CNode)),
]
Here, CNode is used to ...
0
votes
1
answer
47
views
Self referencing Struct type using python Ctypes
I have node class like this:
@dataclass
class TreeNode:
type: NodeType
tok: Token = None
children: list = field(default_factory=list)
Here, children is a list which contains other ...
0
votes
1
answer
38
views
Using ctypes to send an object to c++
I have some python code which generates a tree data structure using the TreeNode class below. Each node can have n-children stored withing the children attribute:
@dataclass
class TreeNode:
type: ...
0
votes
0
answers
34
views
Starting wxFrame using ctypes in Python
I have a DLL file (scisuit_plot_d.dll) and there is a plot function namely c_plot. The DLL has dependencies on a few other DLLs. The signature of c_plot:
extern "C" DLLPLOT PyObject * c_plot(...
0
votes
1
answer
53
views
Defining callback functions for C++in Python
I am trying to write a binding to a C++ function that uses callback function. The callback function looks like.
typedef enum
{
CB_Event_TermRegister = 101,
...
}enSdkCbType;
typedef enum
{
...