Skip to main content

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 DllImprt decorator 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

  1. First, you need to initialize a DLLLoader object 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)
  1. Then, you can load functions from the DLL using the get_function method:
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 ctypes module 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.

  1. Fork the repository.
  2. Clone it to your local machine.
  3. Make your changes and commit them.
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydllmanager-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydllmanager-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for pydllmanager-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93201c078feba669a90a6f9526d834d4a9c2fb13b4aad4ed7830b100df4b681a
MD5 7133676d7db3ffb8e218ac11aa699f09
BLAKE2b-256 9e4c76d267fb10480322c539a58db4545255c85d133e9655b82903ba48787280

See more details on using hashes here.

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

Hashes for pydllmanager-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77cf3178a0dfcb1a7f226836c9dba3c824c776bc35efd3cb680ab17950417643
MD5 d292d317b7b4680d3579a2e8c2532c86
BLAKE2b-256 94ba314c10413b64762e0b6e50b830ac24ee5d4d6a085d42e7fa51ce72f34c9e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page