How to use C enum in Python CTypes?
rozniy
rozniy at gmail.com
Tue Aug 7 00:57:19 EDT 2007
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/ctypes/tutorial.html#bugs-todo-and-non-implemented-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!)
More information about the Python-list
mailing list