ctypes pointer

M

mclaugb

I have a simple function

void adder(double a, double b, double *c){
*c = a+b;
}

i have created a shared dll -- "small_dll4.dll" of it using visual studio.

now i wish to call it from python.
to do so, i have done the following:

libx = cdll("small_dll4.dll", RTLD_GLOBAL)
libx.adder.argtypes = [c_double, c_double, POINTER(c_double)]
libx.adder.restype = None
size=c_double()
zz=libd.adder(3.342, 4, byref(size))

and the result is an access violation!

File "<console>", line 0, in __main__
WindowsError: exception: access violation reading 0x7EF9DB23

I cant figure out what is causing this.
thanks in advance,
Bryan
 
M

mclaugb

I answered this one already.
from ctypes import *

libx = CDLL("small_dll5.dll", RTLD_GLOBAL)

libx = cdll.small_dll4
libx.adder.restype = None
libx.adder.argtypes = [c_double, c_double, POINTER(c_double)]
real=c_double(0)
imag=c_double(0)
zz=libx.adder(3.342,4,byref(size))
print size
 
T

Thomas Heller

mclaugb said:
I have a simple function

void adder(double a, double b, double *c){
*c = a+b;
}

i have created a shared dll -- "small_dll4.dll" of it using visual studio.

now i wish to call it from python.
to do so, i have done the following:

libx = cdll("small_dll4.dll", RTLD_GLOBAL)
libx.adder.argtypes = [c_double, c_double, POINTER(c_double)]
libx.adder.restype = None
size=c_double()
zz=libd.adder(3.342, 4, byref(size))

and the result is an access violation!

File "<console>", line 0, in __main__
WindowsError: exception: access violation reading 0x7EF9DB23

I cant figure out what is causing this.

That should work (and works for me, of course).
Do you have a typo in the above code? libd instead of libx?

Thomas
 
M

mclaugb

Yes, i double defined one of the terms when copying it.
This now works by value and by reference.
Thanks alot,
Bryan


Thomas Heller said:
mclaugb said:
I have a simple function

void adder(double a, double b, double *c){
*c = a+b;
}

i have created a shared dll -- "small_dll4.dll" of it using visual
studio.

now i wish to call it from python.
to do so, i have done the following:

libx = cdll("small_dll4.dll", RTLD_GLOBAL)
libx.adder.argtypes = [c_double, c_double, POINTER(c_double)]
libx.adder.restype = None
size=c_double()
zz=libd.adder(3.342, 4, byref(size))

and the result is an access violation!

File "<console>", line 0, in __main__
WindowsError: exception: access violation reading 0x7EF9DB23

I cant figure out what is causing this.

That should work (and works for me, of course).
Do you have a typo in the above code? libd instead of libx?

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top