I am using Python's CTypes module to import functions from a DLL into
Python. Some of the DLL's functions take enum type arguments, eg:
olDaGetDASS (HDEV hDev, OLSS OlSs, UINT uiElement, PHDASS phDass);
//(this function is in C form)
>From the header file, I found that type OLSS is an enum, like this:
typedef enum olss_tag
{
OLSS_AD,
OLSS_DA,
OLSS_DIN,
OLSS_DOUT,
OLSS_SRL,
OLSS_CT
}
OLSS;
I managed to fudge the HDEV, UINT and PHDASS types as CTypes c_long(),
but I am not sure how translate a C enum into Python...
This site http://python.net/crew/theller/ctype...emented-things
says that enumeration types is not implemented,
"Enumeration types are not implemented. You can do it easily yourself,
using c_int as the base class."
How do I do this? I am fairly new to Python, coming in from C++ (of
which I am utterly sick!) 4 18157
On Tue, 07 Aug 2007 04:57:19 +0000, rozniy wrote:
typedef enum olss_tag
{
OLSS_AD,
OLSS_DA,
OLSS_DIN,
OLSS_DOUT,
OLSS_SRL,
OLSS_CT
}
OLSS;
I managed to fudge the HDEV, UINT and PHDASS types as CTypes c_long(),
but I am not sure how translate a C enum into Python...
This site http://python.net/crew/theller/ctype...emented-things
says that enumeration types is not implemented,
"Enumeration types are not implemented. You can do it easily yourself,
using c_int as the base class."
I would just define constants:
(OLSS_AD,
OLSS_DA,
OLSS_DIN,
OLSS_DOUT,
OLSS_SRL,
OLSS_CT) = map(ctypes.c_int, xrange(6))
Ciao,
Marc 'BlackJack' Rintsch
On Aug 7, 2:11 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Tue, 07 Aug 2007 04:57:19 +0000, rozniy wrote:
typedef enum olss_tag
{
OLSS_AD,
OLSS_DA,
OLSS_DIN,
OLSS_DOUT,
OLSS_SRL,
OLSS_CT
}
OLSS;
I managed to fudge the HDEV, UINT and PHDASS types as CTypes c_long(),
but I am not sure how translate a C enum into Python...
This site http://python.net/crew/theller/ctype...s-todo-and-non...
says that enumeration types is not implemented,
"Enumeration types are not implemented. You can do it easily yourself,
using c_int as the base class."
I would just define constants:
(OLSS_AD,
OLSS_DA,
OLSS_DIN,
OLSS_DOUT,
OLSS_SRL,
OLSS_CT) = map(ctypes.c_int, xrange(6))
Ciao,
Marc 'BlackJack' Rintsch- Hide quoted text -
- Show quoted text -
Wouldn't that assign integer values 0 to 5 to the things? I don't know
if it'll give me the correct results.
On Tue, 07 Aug 2007 02:13:38 -0700, rozniy wrote:
On Aug 7, 2:11 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
>On Tue, 07 Aug 2007 04:57:19 +0000, rozniy wrote:
This site http://python.net/crew/theller/ctype...s-todo-and-non...
says that enumeration types is not implemented,
"Enumeration types are not implemented. You can do it easily yourself,
using c_int as the base class."
I would just define constants:
(OLSS_AD, OLSS_DA, OLSS_DIN, OLSS_DOUT, OLSS_SRL, OLSS_CT) = map(ctypes.c_int, xrange(6))
Wouldn't that assign integer values 0 to 5 to the things?
Yes.
I don't know if it'll give me the correct results.
It should. Enumerations in C are more or less just integer constants.
Ciao,
Marc 'BlackJack' Rintsch
"rozniy" <ro****@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.com...
On Aug 7, 2:11 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
>On Tue, 07 Aug 2007 04:57:19 +0000, rozniy wrote:
typedef enum olss_tag
{
OLSS_AD,
OLSS_DA,
OLSS_DIN,
OLSS_DOUT,
OLSS_SRL,
OLSS_CT
}
OLSS;
I managed to fudge the HDEV, UINT and PHDASS types as CTypes c_long(),
but I am not sure how translate a C enum into Python...
This site http://python.net/crew/theller/ctype...s-todo-and-non...
says that enumeration types is not implemented,
"Enumeration types are not implemented. You can do it easily yourself,
using c_int as the base class."
I would just define constants:
(OLSS_AD, OLSS_DA, OLSS_DIN, OLSS_DOUT, OLSS_SRL, OLSS_CT) = map(ctypes.c_int, xrange(6))
Ciao, Marc 'BlackJack' Rintsch- Hide quoted text -
- Show quoted text -
Wouldn't that assign integer values 0 to 5 to the things? I don't know
if it'll give me the correct results.
Yes, that's how C's and C++'s enums work, unless an override is given (which
I know you can do in C++ for sure). Otherwise, they are just numbers
starting at 0. The size of the intergers (byte, 2 bytes, 4 bytes, etc..) is
implemenation defined I believe, but an int normally works. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Srijit Kumar Bhadra |
last post by:
Hello,
Here are code snippets to create and access shared memory in Python
with and without ctypes module.
With regards,
Srijit
Filename : SharedMemCreate.py
import msvcrt, mmap
|
by: Paul Watson |
last post by:
I need to call some Windows APIs. Is the only way to download ctypes or
the win32 interfaces? Is there any plan to get ctypes batteries into
the standard Python build?
|
by: Gerald Klix |
last post by:
I read the whol email thread carefully and could not find any sentence by
Guido, which states that he does not accept ctypes for the standard library.
He just declined to rewrite winreg. Did I miss...
|
by: follower |
last post by:
This post is mostly Google-bait for anyone else that might want to
compile SpiderMonkey ( libjs / libjs.so / libjs.dylib ) for OS X
(10.4.5 in my case) and then use it with Python's ctypes. I can't...
|
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,...
|
by: Tim Grove |
last post by:
Thanks for your advice Gerdus, but I have tried your suggestion with no
success. It has at least been beneficial to discover a tool which I did
not know about in 'Dependency Walker'; all...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
| |