Ive built the C # DLL (MyTestDll) using the NuGet UnmanagedExports package:
[DllExport("Test", CallingConvention = CallingConvention.Cdecl)] public static string Test(string name) { return "hi " + name + "!"; }
I use it from Python through import of ctypes dll:
path = "C:\\Temp\\Test" os.chdir(path) dll = ctypes.WinDLL("MyTestDll.dll") f = dll.Test f.restype = ctypes.c_char_p print f('qqq')
This is just a fantasy, it works.
Then I added another DLL (NoSenseDll):
namespace NoSenseDll { public class NoSenseClass { public static int Sum(int a, int b) { return a + b; } } }
I started using this NoSenseDll to implement MyTestDll:
[DllExport("Test", CallingConvention = CallingConvention.Cdecl)] public static string Test(string name) { return NoSenseDll.NoSenseClass.Sum(4, 5).ToString(); }
Unfortunately, it does not work. Python says:
WindowsError: [Error -532462766] Windows Error 0xE043435
Ive tried adding C:\\Temp\\Test to the path, but that didn't help.
Ive written a C ++ test:
#include "stdafx.h" #include "windows.h" #include <iostream> #include <string> #include "WinBase.h" typedef char*(__stdcall *f_funci)(const char*); int _tmain(int argc, _TCHAR* argv[]) { int t; std::string s = "C:\\Temp\\Test\\MyTestDll.dll"; HINSTANCE hGetProcIDDLL = LoadLibrary(std::wstring(s.begin(), s.end()).c_str()); f_funci funci = (f_funci)GetProcAddress(hGetProcIDDLL, "Test"); std::cout << "funci() returned " << funci(std::string("qqq").c_str()) << std::endl; std::cin >> t; return EXIT_SUCCESS; }
It works if the second DLL (NoSenseDll) is in the same folder as the C ++ executable. This does not work if I just add the NoSenseDll folder to the PATH.
Dmitry
source share