A DLL management utility for Python by AtomixCore.
Project description
PyDLLManager
PyDLLManager is a Python library designed to simplify the process of loading and interacting with DLL (Dynamic Link Library) files. It allows you to effortlessly load DLLs, call functions, and manage data types using the ctypes module in Python.
Features
- Load DLLs: Easily load DLL files into your Python program.
- Retrieve Functions: Access functions within the DLL with automatic handling of argument and return types.
- Thread Safety: Includes built-in thread safety using
threading.Lock. - Decorator Support: Use the
DllImprtdecorator to automatically load and call functions from DLLs.
Installation
To install PyDLLManager, simply run the following pip command:
pip install pydllmanager
Usage
Basic Usage Example
- First, you need to initialize a
DLLLoaderobject by providing the path to your DLL file.
from pydllmanager import DLLLoader, ctypes_type
dll_path = "path/to/your/dll/file.dll"
loader = DLLLoader(dll_path)
- Then, you can load functions from the DLL using the
get_functionmethod:
add_func = loader.get_function('add', [ctypes_type(int), ctypes_type(int)], ctypes_type(int))
result = add_func(5, 3)
print(result) # Expected output: 8 (depends on the DLL function)
Using the include Decorator
The DllImprt decorator allows you to decorate functions to automatically load them from a DLL.
from pydllmanager import LoaderLibrary
loader = LoaderLibrary("path/to/your/dll/file.dll")
loader.load()
@loader.include()
def add(a: int, b: int) -> int: ... # The function is loaded from the DLL automatically
result = add(5, 3)
print(result) # Expected output: 8
Example Code
from pydllmanager import DLLLoader, ctypes_type, LoaderLibrary
# Using DLLLoader to load and call a function
loader = DLLLoader("path/to/your/dll/file.dll")
subtract_func = loader.get_function('subtract', [ctypes_type(int), ctypes_type(int)], ctypes_type(int))
result = subtract_func(10, 4)
print(result) # Expected output: 6 (depends on the DLL function)
loader = LoaderLibrary("path/to/your/dll/file.dll")
loader.load()
# Using DllImprt decorator
@loader.include()
def multiply(a: int, b: int) -> int: ...
result = multiply(2, 3)
print(result) # Expected output: 6
Exception Handling
PyDLLManager defines a custom exception DLLManagerError to handle any errors during DLL loading or function retrieval. You can use it as follows:
try:
loader = DLLLoader("invalid/path/to/dll.dll")
except DLLManagerError as e:
print(f"Error loading DLL: {e}")
Compatibility
- Supports both 32-bit and 64-bit architectures.
- Compatible with most platforms that support the
ctypesmodule in Python.
Contributing
Contributions to PyDLLManager are welcome! Feel free to fork the repository, submit issues, or open pull requests with improvements or bug fixes.
- Fork the repository.
- Clone it to your local machine.
- Make your changes and commit them.
- Push to your fork and create a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
- Omar Mohamed
GitHub
Version: 1.1.0
Note: Be sure to replace "path/to/your/dll/file.dll" with the actual path to your DLL file in the examples.
thank you for using my project
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydllmanager-0.1.0.tar.gz.
File metadata
- Download URL: pydllmanager-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93201c078feba669a90a6f9526d834d4a9c2fb13b4aad4ed7830b100df4b681a
|
|
| MD5 |
7133676d7db3ffb8e218ac11aa699f09
|
|
| BLAKE2b-256 |
9e4c76d267fb10480322c539a58db4545255c85d133e9655b82903ba48787280
|
File details
Details for the file pydllmanager-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydllmanager-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77cf3178a0dfcb1a7f226836c9dba3c824c776bc35efd3cb680ab17950417643
|
|
| MD5 |
d292d317b7b4680d3579a2e8c2532c86
|
|
| BLAKE2b-256 |
94ba314c10413b64762e0b6e50b830ac24ee5d4d6a085d42e7fa51ce72f34c9e
|