473,692 Members | 2,533 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 16516
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
2493
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
5540
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
4448
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
10264
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
12847
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
4800
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
1135
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
1335
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
8611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8546
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
8969
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
8811
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
8810
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...
0
7635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5822
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();...
1
2981
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1962
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.