Both the dll and the calling file are release versions
Operating system: win11 IDE:visual studio 2022 conda environment: python=3.6 cython=0.29.33 command to generate c file cython demo.pyx -3
demo.pyx
cdef public int add( int str1, int str2):
return int(str1) + int(str2)
Generate dll files code
#include <Windows.h>
#include <Python.h>
#include "demo.h"
extern "C" _declspec(dllexport) int p_add(int a, int b);
int p_add(int a, int b)
{
int p = add(a, b);
return p;
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Py_Initialize();
PyInit_demo();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
Py_Finalize();
break;
}
return TRUE;
}
Callback file code
#include <iostream>
#include <Windows.h>
typedef int(*fun)(int, int);
int main()
{
fun funName = NULL;
HMODULE hMoudle =LoadLibraryA("D:\\stduioProject\\python_gen_dll\\x64\\Release\\python_gen_dll.dll");
{
FreeLibrary(hMoudle);
std::cout << GetLastError(); // error code 1411
return -1;
}
funName = (fun)GetProcAddress(hMoudle, "p_add");
if (funName == NULL)
{
printf("error");
FreeLibrary(hMoudle);
return -10;
}
int f = funName(2, 3);
std::cout << f << std::endl;
FreeLibrary(hMoudle);
}
I'm expecting to return answer 5, but I don't know how to do it.
I lowered python3.8 to 3.6 for testing but still have the same problem