Importing C++ CLR wrapper DLL into Python

JDias 136 Reputation points
2021-01-12T15:59:57.707+00:00

I made a C++ CLR DLL (libwrapper.dll) that imports a C# DLL (lib2.dll):

include <stdio.h>

using "lib2.dll"

extern "C" __declspec(dllexport) int __cdecl getid() {
return (MyCls::getid());
}

This is a kind of hello world program...

Now from python, I do:

from ctypes import *

lib=WinDLL("./libwrapper.dll")
lib.getid.restype=c_int
lib.getid.argtypes=()

print(f"Id = {lib.getid()}")

obtaining the error (in the last line):

Traceback (most recent call last):
File "lw.py", line 7, in <module>
print(f"Id = {lib.getid()}")
OSError: [WinError -532462766] Windows Error 0xe0434352

How can I avoid this error? Is there anything wrong in the code?

What are the options for compiling libwrapper.dll? In the command-line I tried cl libwrapper.cpp /LD /CLR

Developer technologies C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.