ctypes

is there implementation of ctypes(python) in Jruby?

I want to use windows apis in JRuby. Please suggest any api that can do the work of Ctypes(python). ...

What do you make of this Python error?

Here's the error. Traceback (most recent call last): File "_ctypes/callbacks.c", line 295, in 'calling callback function' File "USB2.py", line 454, in ff self.drv_locked = False SystemError: Objects/cellobject.c:24: bad argument to internal function Here's the Python code involved. def drv_send(self, data, size): if not s...

Ctypes pro and con

I have heard that Ctypes can cause crashes (or stop errors) in Python and windows. Should I stay away from their use? Where did I hear? It was back when I tried to control various aspects of windows, automation, that sort of thing. I hear of swig, but I see Ctypes more often than not. Any danger here? If so, what should I watch out for?...

Mutate an integer array using ctypes

Currently I'm in the process of moving a performance bottleneck in my python code to c, to investigate peformance effects. This code will run a simulation, and report back the results to python via ctypes. However, I'm having problems getting my types to match up correctly. Although I'm looking to solve this particular problem, I'm also...

ctype question char**

Hi, I'm trying to figure out why this works after lots and lots of messing about with obo.librar_version is a c function which requires char ** as the input and does a strcpy to passed in char. from ctypes import * _OBO_C_DLL = 'obo.dll' STRING = c_char_p OBO_VERSION = _stdcall_libraries[_OBO_C_DLL].OBO_VERSION OBO_VERSION.restype =...

Different versions of msvcrt in ctypes

In Windows, the ctypes.cdll.msvcrt object automatically exists when I import the ctypes module, and it represents the msvcrt Microsoft C++ runtime library according to the docs. However, I notice that there is also a find_msvcrt function which will "return the filename of the VC runtype library used by Python". It further states, "If y...

Pointers and arrays in Python ctypes

I have a DLL containing a C function with a prototype like this: int c_read_block(uint32 addr, uint32 *buf, uint32 num); I want to call it from Python using ctypes. The function expects a pointer to a chunk of memory, into which it will write the results. I don't know how to construct and pass such a chunk of memory. The ctypes documen...

How do I wrap this C function, with multiple arguments, with ctypes?

Hi everyone! I have the function prototype here: extern "C" void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); I need to write some python to access this function that is in a DLL. I have loaded the DLL, but each of the double* is actually pointing to a variable number of doubles (an array), and ...

"WindowsError: exception: access violation..." - ctypes question

Howdy all - Here is the prototype for a C function that resides in a DLL: extern "C" void__stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); In another thread, I asked about how to properly create and send the necessary arguments to this function. Here is the thread: http://stackoverflow.com/question...

ctypes pointer question

Hi everyone - I was reading the ctypes tutorial, and I came across this: s = "Hello, World" c_s = c_char_p(s) print c_s c_s.value = "Hi, there" But I had been using pointers like this: s = "Hello, World!" c_s = c_char_p() c_s = s print c_s c_s.value Traceback (most recent call last): File "<pyshell#17>", line 1, in <module> c...

Expected LP_c_double instance instead of c_double_Array - python ctypes error

Hi all! I have a function in a DLL that I have to wrap with python code. The function is expecting a pointer to an array of doubles. This is the error I'm getting: Traceback (most recent call last): File "C:\....\.FROGmoduleTEST.py", line 243, in <module> FROGPCGPMonitorDLL.ReturnPulse(ptrpulse, ptrtdl, ptrtdP,ptrfdl,ptrfdP) Argu...

How to read a structure containing an array using Python's ctypes and readinto?

We have some binary files created by a C program. One type of file is created by calling fwrite to write the following C structure to file: typedef struct { unsigned long int foo; unsigned short int bar; unsigned short int bow; } easyStruc; In Python, I read the structs of this file as follows: class easyStruc(Structure...

ctypes memory management: how and when free the allocated resources?

I'm writing a small wrapper for a C library in Python with Ctypes, and I don't know if the structures allocated from Python will be automatically freed when they're out of scope. Example: from ctypes import * mylib = cdll.LoadLibrary("mylib.so") class MyPoint(Structure): _fields_ = [("x", c_int), ("y", c_int)] def foo(): p = ...

Python ctypes and not enough arguments (4 bytes missing)

The function i'm trying to call is: void FormatError (HRESULT hrError,PCHAR pszText); from a custom dll using windll. c_p = c_char_p() windll.thedll.FormatError(errcode, c_p) Results in: ValueError: Procedure probably called with not enough arguments (4 bytes missing) Using cdll instead increases the bytes missing counter to 12....

Problem when getting the content of a listbox with python and ctypes on win32

I would like to get the content of a list box thanks to python and ctypes. item_count = ctypes.windll.user32.SendMessageA(hwnd, win32con.LB_GETCOUNT, 0, 0) items = [] for i in xrange(item_count): text_len = ctypes.windll.user32.SendMessageA(hwnd, win32con.LB_GETTEXTLEN, i, 0) buffer = ctypes.create_string_buffer("", text_len+1)...

Python CreateFile Cannot Find PhysicalMemory

I am trying to access the Physical Memory of a Windows 2000 system (trying to do this without a memory dumping tool). My understanding is that I need to do this using the CreateFile function to create a handle. I have used an older version of win32dd to help me through this. Other documentation on the web points me to using either "\D...

Python ctypes: copying Structure's contents

I want to mimic a piece of C code in Python with ctypes, the code is something like: typedef struct { int x; int y; } point; void copy_point(point *a, point *b) { *a = *b; } in ctypes it's not possible to do the following: from ctypes import * class Point(Structure): _fields_ = [("x", c_int),("y", c_int)] def copy_point(a,...

Access is Denied loading a dll with ctypes on Vista

I'm having issues with using ctypes. I'm trying to get the following project running on Vista. http://sourceforge.net/projects/fractalfrost/ I've used the project before on Vista and had no problems. I don't see any think changed in svn that cause this I'm thinking it's something local to this machine. In fact I'm not able to load d...

Using enums in ctypes.Structure

I have a struct I'm accessing via ctypes: struct attrl { char *name; char *resource; char *value; struct attrl *next; enum batch_op op; }; So far I have Python code like: # struct attropl class attropl(Structure): pass attrl._fields_ = [ ("next", POINTER(attropl)), ("name", c_char_p), ...

How to dereference a memory location from python ctypes?

I want to replicate the following c code in python ctypes: main() { long *ptr = (long *)0x7fff96000000; printf("%lx",*ptr); } I can figure out how to call this memory location as a function pointer but not just do a normal dereference: from ctypes import * """ >>> fptr = CFUNCTYPE(None, None) Traceback (most recent call last): ...