python ctypes - wrap void pointer

Nico R.

I am wrapping a C library into Python via ctypes. At the moment I stuck on one line or more on one parameter. Here the C Code:

void* gVimbaHandleFake = (void*)1;
err = VmbFeatureBoolGet(gVimbaHandleFake, "GeVTLIsPresent", &isGigE );   

The problem is this strange void pointer. In general I know what a void pointer is but this one seems to be "special". If I change the 1 in (void*)1 the program is not working anymore (it is about finding network cameras). It is not crashing but doesnt find the cameras anymore.

I tried many different things, the last tries in Python:

gVimbaHandle = cast(1, c_void_p)
err = self.dll.VmbFeatureBoolGet(byref(gVimbaHandle), "GeVTLIsPresent", byref(isGigE))

also tried the "normal" way:

gVimbaHandle = c_void_p(1)

My program isnt crashing but it tells me that the handle is invalid ... When I looked into the pointer with gVimbaHandle.value I get 1L as output. Could this be the problem, the L for the long datatype?

Does anybody knows how to fix this or can explain the "special" (void*)1 pointer in C to me?

Thank you very much!

Nico R.

So the solution/answer is:

gVimbaHandle = c_void_p(1)
err = self.dll.VmbFeatureBoolGet(gVimbaHandle, "GeVTLIsPresent", byref(isGigE))

thanks @eryksun

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to specify a JNR Pointer like that of python ctypes

Numpy error when converting array of ctypes types to void pointer

How do you wrap a C function that returns a pointer to a malloc'd array with ctypes?

How do you wrap a C function that returns a pointer to a malloc'd array with ctypes?

How do you go from a sip.voidptr (QImage.constBits()) to a ctypes void or char pointer?

Python ctypes arguments with DLL - pointer to array of doubles

expected LP_SHFILEOPSTRUCTW instance instead of pointer to SHFILEOPSTRUCTW (python ctypes)

Converting Python instance to ctypes.c_void_p

Python Ctypes passing pointer for data

Python ctypes pass pointer in structure field to Fortran derived types

Update values of a struct pointer in ctypes python without using a C function

Ctypes: fast way to convert a return pointer to an array or Python list

Convert multiprocessing.Array to ctypes.c_void_p in Python

Ctypes pointer on element in ctypes array

How to cast a ctypes pointer to an instance of a Python class

How to get value of char pointer from Python code wtih ctypes

python: ctypes, read POINTER(c_char) in python

Python -passing imgdata pointer to a function in C using ctypes

How to dereference void* in ctypes?

Python Ctypes Double De-reference Pointer

Pointer from Python (ctypes) to C to save function output

Python ctypes passing string pointer / buffer

Python ctypes pointer and allocated memory

Pointer argument passing in python ctypes

Python ctypes: how to define a callback having a buffer pointer and a length in argument?

Python Bytes to CTypes Void Pointer

Two Python objects holding the same C pointer in ctypes

Declare NULL void pointer locally and pass it to API in ctypes

Mallocing and Freeing in C, but passing the pointer through Python via ctypes