Hi, How to call pointer variable of c++ in python or how to call referance variables?
C pointers from python
Collapse
X
-
If you use better titles, then, even if you leave the specifics out of the question, we'll know better how to help you. And I wont have to change them later.Originally posted by itajitHi, How to call pointer variable of c++ in python or how to call referance variables?Comment
-
I'm not clear on what you need to do or what modules you are using but let me post a couple of lines that I used this week while working with an external DLL that needed C pointers. I only barely understand it at this point because it is new to me, from a friend, and I haven't worked in C in 10 years, but it worked and may lead you in the right direction.
The DLL expected C pointers for input and output to it's functions.
from ctypes import *
Because he's using ctypes.
ExternalLib = windll.LoadLibr ary("LibName.dl l")
To give me access to the DLL functions.
tmpStr = create_string_b uffer(256)
I'm assuming this is a ctypes function that creates a C string pointer.
inx = c_double(1000.0 0)
This DLL works with coordinates, I'm going to pass a double pointer into one of the functions so must declare it as such.
ExternalLib.SetXIn(inx)
SetXIn() is one of the libraries functions so I'm passing in the c double pointer which I set above.
ExternalLib.GetXOut.restyp e = c_double
As I understand this (which I really don't) The GetXOut will be returning a pointer to a C double so I have to declare it as such.
outx = ExternalLib.GetXOut()
Then make the call which now give me a regular double stored in python.
I also read a bit of the python Ctypes Tutorial, though only enough to get a basic understanding for now (which is probably obvious).Comment
-
Awesome, D. I'll move a copy of your post to the new Articles sub section.Originally posted by dshimerI'm not clear on what you need to do or what modules you are using but let me post a couple of lines that I used this week while working with an external DLL that needed C pointers. I only barely understand it at this point because it is new to me, from a friend, and I haven't worked in C in 10 years, but it worked and may lead you in the right direction.
The DLL expected C pointers for input and output to it's functions.
from ctypes import *
Because he's using ctypes.
ExternalLib = windll.LoadLibr ary("LibName.dl l")
To give me access to the DLL functions.
tmpStr = create_string_b uffer(256)
I'm assuming this is a ctypes function that creates a C string pointer.
inx = c_double(1000.0 0)
This DLL works with coordinates, I'm going to pass a double pointer into one of the functions so must declare it as such.
ExternalLib.SetXIn(inx)
SetXIn() is one of the libraries functions so I'm passing in the c double pointer which I set above.
ExternalLib.GetXOut.restyp e = c_double
As I understand this (which I really don't) The GetXOut will be returning a pointer to a C double so I have to declare it as such.
outx = ExternalLib.GetXOut()
Then make the call which now give me a regular double stored in python.
I also read a bit of the python Ctypes Tutorial, though only enough to get a basic understanding for now (which is probably obvious).Comment
Comment