ctypes

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 getdirentries(self, path): self.load_c() ...

How to use C++ classes with ctypes?

Hi there, I'm just getting started with ctypes and would like to use a C++ class that I have exported in a dll file from within python using ctypes. So lets say my C++ code looks something like this: class MyClass { public: int test(); ... I would know create a .dll file that contains this class and then load the .dll file in p...

Introspecting a DLL with python

Hi. I'm currently trying to do some introspection on a DLL with python. I want to create automatically a graphical test interface based on a DLL. I can load my DLL in python quite easily and I call some functions. The main problem is if I call "dir" on the object without calling any method, I've got in result >>> dir(myLib) ['_FuncPtr'...

[VB.NET] Better Way of Getting the Text Value of Cells in an Excel (*.xls) File

I'm trying to write an import function for getting data out of an excel file. How I currently do it is as follows: Private Sub ReadExcel(ByVal childform As PhoneDiag.frmData, ByVal FileName As String) Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet xlA...

Python ctypes & libspeex.dll/libspeex.so; what are the equivilents to #define, typedef, and structs?

I have a reference of the dll file here: http://speex.org/docs/api/speex-api-reference/group__Codec.html What I'm wondering is, in that list, there are a lot of defines. What is the python equivalent, same for the struct class, what are my options for implementing all of this with ctypes? Typedefs? I'm relatively inexperienced with...

Accessing xrange internal structure

I'm trying to use ctypes to extract data from internal python structures. Namely, I'm trying to read the 4 fields in an xrange: typedef struct { PyObject_HEAD long start; long step; long len; } rangeobject; Is there any standard way of getting at such fields within python itself? ...

Help ctypes.windll.dnsapi.DnsQuery_A

Hi, I have trouble with DnsQuery API, the *ppQueryResultsSet parameter troubles me. Can anyone show me an example of how to make correct DLL calls in python? import ctypes from ctypes import wintypes from windns_types import DNS_RECORD, IP4_ARRAY #declared here http://pastebin.com/f39d8b997 def DnsQuery(host, type, server, opt=0): ...

How to pack and unpack using ctypes (Structure <-> str)

This might be a silly question but I couldn't find a good answer in the docs or anywhere. If I use struct to define a binary structure, the struct has 2 symmetrical methods for serialization and deserialization (pack and unpack) but it seems ctypes doesn't have a straightforward way to do this. Here's my solution, which feels wrong: fr...

pygst - glimagesink callback

I'm trying to use 'glimagesink' element with python. The element (which is GObject inside) has client-draw-callback property which should (in C++ at least) contain a function (bool func(uint t, uint w, uint h)) pointer. I've tried element.set_property('client-draw-callback', myfunc), and creating function pointer with ctypes, but every t...

Calling a function using ctypes with pointers to structs

Hi! I am trying to call a C function sitting in a shared object from python, and using ctypes seems to be the best way of accomplishing this. I have to pass derived types to this function, with the following function prototype: int MyFunc (Config *config, int *argc, char **argv ) The Config struct is defined as typedef struct{ char ...

Python ctypes: initializing c_char_p()

I wrote a simple C++ program to illustrate my problem: extern "C"{ int test(int, char*); } int test(int i, char* var){ if (i == 1){ strcpy(var,"hi"); } return 1; } I compile this into an so. From python I call: from ctypes import * libso = CDLL("Debug/libctypesTest.so") func = libso.test func.res_type = c_int ...

Contructing python function callable from C , with input parameter having *output* sematics

The use case is the following: Given a (fixed, not changeable) DLL implemented in C Wanted: a wrapper to this DLL implemented in python (chosen method: ctypes) Some of the functions in the DLL need synchronization primitives. To aim for maximum flexibility, the designers of the DLL completely rely on client-provided callbacks. More p...

WindowsError: [Error 126] The specified module could not be found

Hello All I am loading a dll in python using following code. if os.path.exists(dll_path): my_dll = ctypes.cdll.LoadLibrary(dll_path) But i am continuously getting the following error WindowsError: [Error 126] The specified module could not be found dll is present at the specified path...but i didn't understand why i am gettin...

Wrapping a C library in Python: C, Cython or ctypes?

I want to call a C library from a Python application. I don't want to wrap the whole API, only the functions and datatypes that are relevant to my case. As I see it, I have three choices: Create an actual extension module in C. Probably overkill, and I'd also like to avoid the overhead of learning extension writing. Use Cython to expos...

ctypes WriteProcessMemory() fails, help!

I have been trying to get this function working for some time now with no luck. def write_memory(self, address, data): PROCESS_ALL_ACCESS = 0x001F0FFF count = c_ulong(0) length = len(data) c_data = c_char_p(data[count.value:]) null = c_int(0) windll.kernel32.SetLastError(10000) if not windll.kernel32.WritePro...

Cannot use Python 2.6 C interface anymore, but 2.5 works.

I just noticed that I cannot use the Python 2.6 dll anymore. Python 2.5 works just fine. import ctypes py1 = ctypes.cdll.python25 py2 = ctypes.cdll.python26 # ctypes.cdll.LoadLibrary("libpython2.6.so") in linux py1.Py_Initialize() py2.Py_Initialize() # segmentation fault in Linux py1.PyRun_SimpleString("print 'hello world'") # this ...

Python ctypes callback function to SWIG

I have a SWIG C++ function that expects a function pointer (WNDPROC), and want to give it a Python function that has been wrapped by ctypes.WINFUNCTYPE. It seems to me that this should be compatible, but SWIG's type checking throws an exception because it doesn't know that the ctypes.WINFUNCTYPE type is acctually a WNDPROC. What can I ...

Python ctypes addressof CFuncType

Related to my other question How can I get the address (acctual function pointer) to a CFuncType object? addressof() does not report the correct address. C code: extern "C" _declspec(dllexport) int addr(int (*func)()) { int r = (int)func; return r; } Python code: def test(): return 42 t = CFUNCTYPE(c_int) f = t(test) pr...

user pointer in python

*I am trying to display preview from webcam captured using v4l. Here is an idea of how the code looks like: from ctypes import * from v4l2 import * from Image import fromstring from Tkinter import Tk, Label from ImageTk import PhotoImage from ctypes.util import find_library libc = CDLL(find_library('c')) posix_memalign = libc.posix_me...

How to get IUnknown from WDM driver CreateInstance

In documentation (C++ example) LUnknown* pIUnknown = CreateInstance(slot); I try this >> import ctypes >> print type(ctypes.cdll.lcomp.CreateInstance(0)) <type 'int'> How to get IUNKNOWN and QueryInterface? ...