Все вопросы: [ctypes]

62 вопросов

похожие теги: ctype
4
голосов
1ответов
2108 просмотров

Python: Extracting data from buffer with ctypes

I am able to successfully call a function with ctypes in Python. I now have a buffer that is filled with Structures of data I want to extract. What is the best strategy for this? Anything else I should post? Function: class list(): def __init__(self): #[...] def getdirentrie...

15
голосов
1ответов
17797 просмотров

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 = CFUNCTYP...

11
голосов
2ответов
16465 просмотров

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(attro...

1
голосов
1ответов
1075 просмотров

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 thi...

9
голосов
5ответов
9579 просмотров

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...

0
голосов
1ответов
1668 просмотров

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 documentatio...

0
голосов
2ответов
1017 просмотров

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 = c...

4
голосов
3ответов
6930 просмотров

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 ...

10
голосов
1ответов
4493 просмотров

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", ...

6
голосов
2ответов
4367 просмотров

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 f...

3
голосов
2ответов
12401 просмотров

Expected LP_c_double instance instead of c_double_Array - python ctypes error

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(ptrpu...

1
голосов
1ответов
1136 просмотров

ctypes pointer question

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#1...

6
голосов
2ответов
25030 просмотров

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

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: How ...

0
голосов
2ответов
973 просмотров

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

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 numbe...

39
голосов
4ответов
53381 просмотров

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 ...

8
голосов
1ответов
2369 просмотров

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 ...

1
голосов
2ответов
2163 просмотров

ctype question char**

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_D...

4
голосов
1ответов
2908 просмотров

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 ...

7
голосов
4ответов
4475 просмотров

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...

2
голосов
2ответов
2758 просмотров

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. de...

1
голосов
3ответов
135 просмотров

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).

5
голосов
1ответов
3830 просмотров

Why does import of ctypes raise ImportError?

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import ctypes Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python26\lib\ctyp...

2
голосов
2ответов
904 просмотров

How to read/copy ctype pointers into python class?

This is a kind of follow-up from my last question if this can help you. I'm defining a few ctype structures class EthercatDatagram(Structure): _fields_ = [("header", EthercatDatagramHeader), ("packet_data_length", c_int), ("packet_data", POINTER(c_ubyte)), ...

10
голосов
3ответов
1976 просмотров

python ctype recursive structures

I've developped a DLL for a driver in C. I wrote a test program in C++ and the DLL works fine. Now I'd like to interract with this DLL using Python. I've successfully hidden most of the user defined C structures but there is one point where I have to use C structures. I'm rather new to python so...

6
голосов
6ответов
2659 просмотров

IO completion port key confusion

I'm writing an IO completion port based server (source code here) using the Windows DLL API in Python using the ctypes module. But this is a pretty direct usage of the API and this question is directed at those who have a knowledge of IOCP, not Python. As I understand the documentation for Crea...

2
голосов
3ответов
779 просмотров

Problem running functions from a DLL file using ctypes in Object-oriented Python

I sure hope this won't be an already answered question or a stupid one. Recently I've been programming with several instruments. Trying to communicate between them in order to create a testing program. However I've encoutered some problems with one specific instrument when I'm trying to call func...

3
голосов
2ответов
1663 просмотров

Guides for implementing a foreign function interface

Right now I'm working on a scripting language that doesn't yet have a FFI. I'd like to know what's the most convenient way to get it in, assuming that I'd like to write it like cool geeks do - I'd like to write the FFI in the scripting language itself. The programming language I need to interfac...

8
голосов
3ответов
16795 просмотров

Python: доступ к функции DLL с использованием ctypes - доступ по функции * имя * не выполняется

myPythonClient (ниже) хочет вызвать функцию ringBell (загруженную из DLL с использованием ctypes). Однако попытка доступа к ringBell через его имя приводит к AttributeError. Почему? RingBell.h содержит namespace MyNamespace { class MyClass { public: st...

4
голосов
1ответов
3101 просмотров

USB - синхронизация против асинхронного против полуасинхронного

Обновления: Я написал асинхронную версию C, и она работает как надо. Оказывается, проблема со скоростью возникла из-за Python GIL. Есть способ настроить его поведение. sys.setcheckinterval (интервал) Установка нулевого интервала (по умолчанию 100) устраняет проблему низкой скорости. Теп...

2
голосов
3ответов
2482 просмотров

Некоторые помогают понять асинхронные операции USB с libusb-1.0 и ctypes

Хорошо. Я понял. transfer.flags должен быть байтом, а не целым. Я такой глупый. Теперь я получаю код ошибки от ioctl, errno 16, что, как мне кажется, означает, что устройство занято. Какой трудоголик. Я спрашивал в списке рассылки libusb. Вот что у меня есть на данный момент. На самом деле эт...