471,342 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

ctypes pointer

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
Jun 19 '07 #1
3 4135
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
"mclaugb" <mc*****@nospm.yahoo.comwrote in message
news:f5**********@gemini.csx.cam.ac.uk...
>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

Jun 19 '07 #2
mclaugb schrieb:
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

Jun 19 '07 #3
Yes, i double defined one of the terms when copying it.
This now works by value and by reference.
Thanks alot,
Bryan
"Thomas Heller" <th*****@ctypes.orgwrote in message
news:ma***************************************@pyt hon.org...
mclaugb schrieb:
>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

Jun 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Thomas Heller | last post: by
12 posts views Thread by p.lavarre | last post: by
1 post views Thread by sjdevnull | last post: by
3 posts views Thread by Chris AtLee | last post: by
6 posts views Thread by Jack | last post: by
2 posts views Thread by Jean-Paul Calderone | last post: by
5 posts views Thread by castironpi | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.