I wrote simple C++ Dll ( win32 ) and i change the properties to be ‘Common Language Runtime Support (/clr)’ –
I created new Simple winform project ( C# 4.0 ) and i created reference to the C++ project ( the C++ DLL ).
Now i can’t see the C++ dll in the C# project – i cant use it and i dont know why.
If you have, for example, this unmanaged function:
If you want to make it visible to managed code you have to wrap (as first, simple, step) it into a managed class:
This is a simple exam, if you have to interop with complex type you may need to wrap them all. For example if you have to interop with a function that accepts a string you have to manage this. Usually I use a class like this:
Using this class you can call a function like void
foo(LPCSTR pszText)withfoo(UnamangedString(myManagedString)). More complex are the calls you have to do and more code you have to write to interop between them.Note: simply exposing a 1:1 managed interface to unmanaged functions will make your C# code harder to read, I suggest you write a true OO interface to hide underlying implementation.