473,322 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ctypes: how to make a structure pointer to point to a buffer

first, I'm try the POINTER to convesion the pointer type. but failed.

class STUDENT(Structure):
_fields_ = [('name', c_int),
('id', c_int),
('addition', c_ubyte)]

buffer = c_byte * 1024
student_p = cast(buffer, POINTER(STUDENT))

The parameter of the POINTER must be ctypes type.
How could I attach the buffer pointer to the structure STUDENT ?

Apr 23 '07 #1
1 6158
人言落日是天涯,望极天涯不见家 wrote:
first, I'm try the POINTER to convesion the pointer type. but failed.

class STUDENT(Structure):
_fields_ = [('name', c_int),
('id', c_int),
('addition', c_ubyte)]

buffer = c_byte * 1024
student_p = cast(buffer, POINTER(STUDENT))

The parameter of the POINTER must be ctypes type.
How could I attach the buffer pointer to the structure STUDENT ?
I think it should work like this:

from ctypes import *

class STUDENT(Structure):
_fields_ = [('name', c_int),
('id', c_int),
('addition', c_ubyte)]

buffer = (c_byte * 1024)()
buffer_p = pointer(buffer)
student_p = cast(buffer_p, POINTER(STUDENT))

print student_p
Diez
Apr 23 '07 #2

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

Similar topics

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...
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...
4
by: Neal Becker | last post by:
In an earlier post, I was interested in passing a pointer to a structure to fcntl.ioctl. This works: c = create_string_buffer (...) args = struct.pack("iP", len(c), cast (pointer (c),...
3
by: waldek | last post by:
Hi, I'm using C dll with py module and wanna read value (buffer of bytes) returned in py callback as parameter passed to dll function. -------------------------------------------------- def ...
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...
3
by: castironpi | last post by:
Is there a way to initialize a ctypes Structure to point to an offset into a buffer? I don't know if the way I'm doing it is supported.
3
by: =?GB2312?B?0rvK18qr?= | last post by:
Hi all, Recently I asked a question on this group: I got these suggestion: 1) try construct
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.