473,657 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: ctypes - swig - pointer

On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <ge*******@gmai l.comwrote:
>I've a problem with dll function colled with python/ctypes. My
functions (C) requred a typedef int "value_type " in tree different
way:
same as value_type; - mydll.foo1(valu e_type)
same as *value_type; - mydll.foo2(*val ue_type)
same as **value_type; - mydll.foo3(**va lue_type)

How can pass it in python. If i do that:
rules=POINTER( value_type)
opr=rsl.Streng thOfRules(rules ,10)
R=POINTER(rule s)
POINTER takes a class and returns a new class which represents a pointer
to input class.

pointer takes an instance and returns a new object which represents a
pointer to that instance.

Jean-Paul
Jun 30 '08 #1
2 16504
On 30 Giu, 18:26, Jean-Paul Calderone <exar...@divmod .comwrote:
On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonom...@gmai l.comwrote:
I've a problem with dll function colled with python/ctypes. My
functions (C) requred a typedef int "value_type " in tree different
way:
same as value_type; - mydll.foo1(valu e_type)
same as *value_type; - mydll.foo2(*val ue_type)
same as **value_type; - mydll.foo3(**va lue_type)
How can pass it in python. If i do that:
rules=POINTER(v alue_type)
opr=rsl.Strengt hOfRules(rules, 10)
R=POINTER(rules )

POINTER takes a class and returns a new class which represents a pointer
to input class.

pointer takes an instance and returns a new object which represents a
pointer to that instance.

Jean-Paul
so,
if I write this:
p=pointer(value _type)
mydll.foo1(p)
could be correct but python say me:
TypeError: _type_ must have storage info
what does mean?

thank you

gima
Jun 30 '08 #2

"gianluca" <ge*******@gmai l.comwrote in message
news:58******** *************** ***********@z72 g2000hsb.google groups.com...
On 30 Giu, 18:26, Jean-Paul Calderone <exar...@divmod .comwrote:
>On Mon, 30 Jun 2008 09:13:42 -0700 (PDT), gianluca <geonom...@gmai l.com>
wrote:
>I've a problem with dll function colled with python/ctypes. My
functions (C) requred a typedef int "value_type " in tree different
way:
same as value_type; - mydll.foo1(valu e_type)
same as *value_type; - mydll.foo2(*val ue_type)
same as **value_type; - mydll.foo3(**va lue_type)
>How can pass it in python. If i do that:
rules=POINTER( value_type)
opr=rsl.Streng thOfRules(rules ,10)
R=POINTER(rule s)

POINTER takes a class and returns a new class which represents a pointer
to input class.

pointer takes an instance and returns a new object which represents a
pointer to that instance.

Jean-Paul

so,
if I write this:
p=pointer(value _type)
mydll.foo1(p)
could be correct but python say me:
TypeError: _type_ must have storage info
what does mean?

thank you

gima
It means you cannot create a pointer to a type, you need to provide an
instance of a type:
>>from ctypes import *
px=pointer(c_ int)
Traceback (most recent call last):
File "<interacti ve input>", line 1, in <module>
File "C:\dev\python\ lib\ctypes\__in it__.py", line 282, in pointer
return POINTER(type(in st))(inst)
File "C:\dev\python\ lib\ctypes\__in it__.py", line 226, in POINTER
{'_type_': cls})
TypeError: _type_ must have storage info
>>x=c_int(5) # make an instance (C equiv. is "int x=5;")
px=pointer( x) # int* px = &x;
ppx=pointer(p x) # int** ppx = &px;
x
c_long(5)
>>px
<ctypes.LP_c_lo ng object at 0x00E87350>
>>ppx
<ctypes.LP_LP_c _long object at 0x00E873A0>

--Mark

Jul 1 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2487
by: Thomas Heller | last post by:
ctypes 0.9.2 released - Oct 28, 2004 ==================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call functions exposed from dlls/shared libraries and has extensive facilities to create, access and manipulate
3
5535
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 Simple MAPI module was Ian's completed version of an example I had posted in an earlier message. In it I had to set some pointer fields in a C structure to NULL. I was not happy with the solution I used so I made an inquiry on the ctypes-users...
2
4442
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c */ #include <time.h>
1
10231
by: marc.wyburn | last post by:
hi all and before I start I apologise if I have this completely muddled up but here goes. I'm trying to call functions from a dll file in a python script but I can't work out what functions are available. I'm using ctypes. I've tried using dir(ctypes_object) but the resultant output looks like a list of standard functions and not the ones I'm looking for. Also how can I tell if the dll was written in C or C++ as I understand C++ dlls...
6
12809
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 I should declare the return type of the functions and read the fields. Any hint is appreciated. typedef struct { char *country_short; char *country_long;
8
4797
by: gianluca | last post by:
Hy, I need help about use dll with ctypes. I've compiled my dll C library and I copied it in c:\windows\system32. When I load it with "myDLL=cdll.LoadLibrary(find_library("myDLL.dll"))" It seem all OK but python don't see the dll function. with dir(myDLL) I've only this: Could anybody help me Thanks
0
1134
by: gianluca | last post by:
I've a problem with dll function colled with python/ctypes. My functions (C) requred a typedef int "value_type" in tree different way: same as value_type; - mydll.foo1(value_type) same as *value_type; - mydll.foo2(*value_type) same as **value_type; - mydll.foo3(**value_type) How can pass it in python. If i do that: rules=POINTER(value_type) opr=rsl.StrengthOfRules(rules,10)
2
1333
by: Sells, Fred | last post by:
Diez wrote... You're right the ctypes does seem more pythonesque; however I'm still stuck trying return all these parameters that the c api uses. my ctypes code is below. It just quits running when I try to print one of the args I did a pass byref on, no error out, nothing. admittedly I'm a newbie to ctypes and not much of a c programmer but I could sure use some help. my ctypes test code follows... from ctypes import * '''...
0
163
by: Terry Reedy | last post by:
dudeja.rajat@gmail.com wrote: Ugh ;-) I have the impression that SWIG has multiple backends for different languages. There is one for automating much of the work of producing an extension module. I presume there could be one, if not already, that produced Python/cytpe code instead of C code. That would be a nice
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.