472,981 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 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 4208
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas Heller | last post by:
ctypes 0.9.1 released - Sept 14, 2004 ===================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call...
3
by: Lenard Lindstrom | last post by:
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This...
12
by: p.lavarre | last post by:
Q: The C idea of (pv != NULL) is said most directly in Python ctypes how? A: We are of course supposed to write something like: def c_not_null(pv): return (ctypes.cast(pv,...
3
by: p.lavarre | last post by:
Subject: Python CTypes translation of (pv != NULL) And so then the next related Faq is: Q: How should I test for ((void *) -1)? A: (pv == 0xffffFFFF) works often.
1
by: sjdevnull | last post by:
Hey, I'm trying to wrap GNU readline with ctypes (the Python readline library doesn't support the callback interface), but I can't figure out how to set values to a variable inside the library. ...
3
by: Chris AtLee | last post by:
Sorry for the repeat post...I'm not sure if my first post (on May 30th) went through or not. I've been trying to write a PAM module using ctypes. In the conversation function (my_conv in the...
0
by: malen | last post by:
Hi all! I'm building mouse movement filter program for Windows and Mac OS X. In Windows I use ctypes.windll.user32.getCursorPos(pointer) and ctypes.windll.user32.setCursorPos(x,y) to get and set...
6
by: Jack | last post by:
I'm not able to build IP2Location's Python interface so I'm trying to use ctypes to call its C interface. The functions return a pointer to the struct below. I haven't been able to figure out how...
2
by: Jean-Paul Calderone | last post by:
On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonomica@gmail.comwrote: POINTER takes a class and returns a new class which represents a pointer to input class. pointer takes an instance...
5
by: castironpi | last post by:
Hi all, I have a mmap and a data structure in it. I know the structure's location in the mmap and what structure it is. It has a ctypes definition. I want to initialize a ctypes object to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.