Hi,
Is it possible to define a packed C structure in python and pass it to the c
module, or should the wrapper do that ?
Regards,
Philippe 8 1964
Philippe Martin wrote: Is it possible to define a packed C structure in python and pass it to the c module, or should the wrapper do that ?
You can create a packed structure using string concatenation, and with
the help of the struct module. However, this gives you a string object
in the end, which you still need to pass into your C library.
It is better to fill the struct in the wrapper.
Regards,
Martin
Thanks,
It's a pretty big structure: painfull to pass each item as a param.
Regards,
Philippe
"Martin v. Löwis" wrote: Philippe Martin wrote: Is it possible to define a packed C structure in python and pass it to the c module, or should the wrapper do that ?
You can create a packed structure using string concatenation, and with the help of the struct module. However, this gives you a string object in the end, which you still need to pass into your C library.
It is better to fill the struct in the wrapper.
Regards, Martin
Philippe Martin wrote: It's a pretty big structure: painfull to pass each item as a param.
So how else would you like to pass them? Define the API you want,
and then just implement it. It still shouldn't require to define
the layout in Python.
Regards,
Martin
Well,
The call actually is an IOCtl: depending on the control code, the structure
has a different format.
Although the number of control codes/structures is finite, it would make the
wrapper function fairly large.
You seem to think that building the structure from python would be a
mistake: why is that ?
PS: the wrapper also has to work under multiple OSs
Regards,
Philippe
"Martin v. Löwis" wrote: Philippe Martin wrote: It's a pretty big structure: painfull to pass each item as a param.
So how else would you like to pass them? Define the API you want, and then just implement it. It still shouldn't require to define the layout in Python.
Regards, Martin
On Apr 14, 2006, at 9:44 AM, Philippe Martin wrote: Thanks,
It's a pretty big structure: painfull to pass each item as a param.
Regards,
Philippe
Maybe this can do something for you? http://pyconstruct.sourceforge.net/
Jay P.
Philippe Martin wrote: The call actually is an IOCtl: depending on the control code, the structure has a different format.
Ah. In that case, I recommend to use the ioctl module; you won't need a
C wrapper, then.
Although the number of control codes/structures is finite, it would make the wrapper function fairly large.
*Some* code to handle this will be very large, regardless of how you
write it.
You seem to think that building the structure from python would be a mistake: why is that ?
It's very error-prone. You have to match the C structure layout of the
compiler precisely, and you even have to get the alignment right,
something that can't be done reliably in Python.
PS: the wrapper also has to work under multiple OSs
That makes it worse: now you not only have to match the C compiler's
expectation on a single processor, but on different ones.
Perhaps you should be using ctypes.
Regards,
Martin
I misslead you: it is a smart card-style ioctl ...
Philippe
"Martin v. Löwis" wrote: Philippe Martin wrote: The call actually is an IOCtl: depending on the control code, the structure has a different format.
Ah. In that case, I recommend to use the ioctl module; you won't need a C wrapper, then.
Although the number of control codes/structures is finite, it would make the wrapper function fairly large.
*Some* code to handle this will be very large, regardless of how you write it.
You seem to think that building the structure from python would be a mistake: why is that ?
It's very error-prone. You have to match the C structure layout of the compiler precisely, and you even have to get the alignment right, something that can't be done reliably in Python.
PS: the wrapper also has to work under multiple OSs
That makes it worse: now you not only have to match the C compiler's expectation on a single processor, but on different ones.
Perhaps you should be using ctypes.
Regards, Martin
I'll take a look,
thanks.
Jay Parlar wrote: On Apr 14, 2006, at 9:44 AM, Philippe Martin wrote:
Thanks,
It's a pretty big structure: painfull to pass each item as a param.
Regards,
Philippe
Maybe this can do something for you?
http://pyconstruct.sourceforge.net/
Jay P. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bryan G |
last post by:
Hi, I'm working on a VB project which involves using C
library functions which take struct pointers as args, and
I keep running into this error when trying to pass either
an IntPtr or a Structure ByRef to the functions.
An unhandled exception of
type 'System.Runtime.InteropServices.MarshalDirectiveExcept
ion' occurred in ConsoleApplication1.exe
Additional information: PInvoke restriction: can not
|
by: Steve |
last post by:
Hello,
I created a public Structure in a Standard Module and also
an array of Structures. Then I load data into the array
of structures in a public sub that I call on the Form load
event. Next I have a class, and I want to pass a
structure member from my array of Structures to the class
constructor. In the form I instantiate a class object.
Module1
|
by: Dave Cullen |
last post by:
I want to call a function using my own data type as an argument. The
declaration for my function looks like this:
Public Function CreateCardInfo(ByVal data As WoData)
VB.NET balks at this, saying:
'data' cannot expose a Friend type outside of the Public class
'frmMain'.
|
by: parag.kanade |
last post by:
I have a packet structure which has a field of Integer arrays, that is
packed struct
{
int a;
char b;
int count;
}foo;
I need to initialize all the entries of count to a particular value,
|
by: Daniel Rudy |
last post by:
What is the difference between packed and unpacked structs?
--
Daniel Rudy
Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m
Why geeks like computers: look chat date touch grep make unzip
| |
by: sharadvasista |
last post by:
I have a structure
typedef struct t_abcd
{
int a;
int b;
int c;
} abcd;
I have to pass the structure to another function. I can do this in two ways.
|
by: Sikandar |
last post by:
Hi,
I am beginner in C. Pls let me know what is packed array in C. Where
is it used?
Thanks,
Sikandar
|
by: Kris Kennaway |
last post by:
I want to make use of UNIX credential passing on a local domain socket
to verify the identity of a user connecting to a privileged service.
However it looks like the socket module doesn't implement
sendmsg/recvmsg wrappers, and I can't find another module that does this
either. Is there something I have missed?
Kris
|
by: Travis |
last post by:
Hi all -
Most of my experience in c++ has been upper level. I am just now
getting into lower level stuff and I see this alot
class foo {
....
} __attribute__((aligned(1), packed));
I am having trouble finding any documentation online that explains
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |