简体   繁体   中英

How to declare a variable of a type that is defined in a DLL or shared library?

I want to define a instance of some structure or variable type that is defined in a DLL to send it to a function using 'ctypes'. I know I can define similar variable/structure types in python/ctypes and then send them but it takes a lot of time to define all types in my code. is there any way to just declare variables of inside DLL types just like c_int or c_char_p in ctypes?

Which DLL do you use ?

For the winapi.dll, ctypes provides also some useful structures like HWND, RECT, MSG,... See ctypes.wintypes for more info.

You can also check for ctypeslib which parse a C file for structure and data types.

In my experience, I hardly write down more than a few C structures when calling a dll from python script/program, so it is not an issue. If you have to use a lot of in-DLL structures, you may want to use SWIG instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM