There are several ways to loaded shared libraries into the Python process. One way is to instantiate one of the following classes:
name, mode=DEFAULT_MODE, handle=None) |
int
.
name, mode=DEFAULT_MODE, handle=None) |
stdcall
calling convention, and are assumed to return the windows specific
HRESULT code. HRESULT values contain information
specifying whether the function call failed or succeeded, together
with additional error code. If the return value signals a
failure, an WindowsError is automatically raised.
name, mode=DEFAULT_MODE, handle=None) |
stdcall
calling convention, and are assumed to return int
by default.
On Windows CE only the standard calling convention is used, for convenience the WinDLL and OleDLL use the standard calling convention on this platform.
The Python GIL is released before calling any function exported by these libraries, and reaquired afterwards.
name, mode=DEFAULT_MODE, handle=None) |
Thus, this is only useful to call Python C api functions directly.
All these classes can be instantiated by calling them with at least
one argument, the pathname of the shared library. If you have an
existing handle to an already loaded shard library, it can be passed
as the handle
named parameter, otherwise the underlying platforms
dlopen
or LoadLibrary function is used to load the library
into the process, and to get a handle to it.
The mode parameter can be used to specify how the library is
loaded. For details, consult the dlopen(3)
manpage, on Windows,
mode is ignored.
Instances of these classes have no public methods, however __getattr__ and __getitem__ have special behaviour: functions exported by the shared library can be accessed as attributes of by index. Please note that both __getattr__ and __getitem__ cache their result, so calling them repeatedly returns the same object each time.
The following public attributes are available, their name starts with an underscore to not clash with exported function names:
Shared libraries can also be loaded by using one of the prefabricated objects, which are instances of the LibraryLoader class, either by calling the LoadLibrary method, or by retrieving the library as attribute of the loader instance.
dlltype) |
dlltype
should be one
of the CDLL, PyDLL, WinDLL, or OleDLL types.
__getattr__ has special behaviour: It allows to load a shared library by accessing it as attribute of a library loader instance. The result is cached, so repeated attribute accesses return the same library each time.
name) |
These prefabricated library loaders are available:
For accessing the C Python api directly, a ready-to-use Python shared library object is available:
int
, which is of course not always the truth, so you have to
assign the correct restype attribute to use these functions.
See About this document... for information on suggesting changes.