Good day!
I'm trying to make my little test dll to work in python code, using ctypes.
Here is my cppmul.cpp:
#include <iostream>
using namespace std;
extern "C" __declspec(dllexport) float cmul(int int_param, float float_param) {
float return_value = int_param * float_param;
std::cout << "In cmult: int: " << int_param << ", float: " << float_param << ", returning: " << return_value << std::endl;
return return_value;
}
extern "C" __declspec(dllexport) void hello() {
std::cout << "wheee" << std::endl;
return;
}
Which I build with the next script:
g++ -c cppmul.cpp
g++ -shared -o libcppmul.dll -Wl,-out-implib,libcppmul.a -Wl,--export-all-symbols -Wl,--enable-auto-image-base cppmul.o
Then in the python script I just load dll and trying to call function:
# loads great
lib = ctypes.WinDLL(libname, winmode=1)
lib.hello.restype = None
# exception here
lib.hello()
And get: OSError: exception: access violation writing 0x0000000000009658
OS Windows 10 x64, Python 3.9 x64.
Any suggestions?
I think maybe the problem is a some kind of type mismatch? But there are no types in the hello() function, only a void as return and an empty argument list.