Код: Выделить всё
Traceback (most recent call last):
File "e:\My Apps\Python\Telegram_Bots\Calculator\main.py", line 6, in
lib = CDLL("E:\My Apps\Python\Telegram_Bots\Calculator\lib.dll")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\KHATAM_PC\AppData\Local\Programs\Python\Python311\Lib\ctypes\__init__.py", line 376, in __init__
self._handle = _dlopen(self._name, mode)
^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: Could not find module 'E:\My Apps\Python\Telegram_Bots\Calculator\lib.dll' (or one of its dependencies). Try using the full path with constructor syntax.
Код: Выделить всё
.dll
Код: Выделить всё
lib.hpp
Код: Выделить всё
// #pragma once
#ifndef MATH_DLL_API
#define MATH_DLL_API
#ifdef _WIN32
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
#include
#include
extern "C" {
DLL_EXPORT int precedence(char o);
DLL_EXPORT float calc(float a, float b, char o);
DLL_EXPORT void calculate(std::vector& values, std::vector& ops);
DLL_EXPORT float evaluate(std::string e);
}
#endif // MATH_DLL_API
< /code>
lib.cpp
#include "lib.hpp"
#include
#include
extern "C" {
DLL_EXPORT int precedence(char o) { ... }
DLL_EXPORT float calc(float a, float b, char o) { ... }
DLL_EXPORT void calculate(std::vector& values, std::vector& ops) { ... }
DLL_EXPORT float evaluate(std::string e) { ... }
}
< /code>
And finaly, the python script:
from ctypes import c_char, c_int, c_float, c_char_p, c_void_p, CDLL, cdll, POINTER
lib = CDLL("E:\My Apps\Python\Telegram_Bots\Calculator\lib.dll")
lib.evaluate.argtypes = [c_char_p]
lib.evaluate.restype = c_float
lib.calculate.argtypes = [POINTER(c_float), POINTER(c_char)]
lib.calculate.restype = c_void_p
lib.calc.argtypes = [c_float, c_float, c_char]
lib.calc.restype = c_float
lib.precedence.argtypes = [c_char]
lib.precedence.restype = c_int
< /code>
Can anybody help please?
Подробнее здесь: https://stackoverflow.com/questions/795 ... d-dll-file