Set an unmanaged C ++ class library in C #

In fact, I have two unregistered C ++ libraries, one of which uses the other. Both of them are quite large, so rewriting is not an option for me.

I read something about creating a C ++ managed library that wraps arround unmanaged code. But I don’t understand how to start, and how to combine all this in one project ...

Are there any walkthroughs or good ones to easily understand examples of how to do this?

TIA

+3
source share
5 answers

, COM- ++, ATL. , . Microsoft , ++ (, Windows 7). COM .NET/# (. ). , COM, .

+3

, , .

++-, :

  • SWIG, # PInvoke ++. , , . , - .

  • C , DLL PInvoke, #. , , . ++, , , , - DoTheConversion(LPWSTR inputFile). # .

+1

++ . , Managed ++, ++ .. # ++ , .net-. P/Invoke .

+1

: ijw " ", ++ ++. pinvoke.

pinvoke, -

#

somefunction("str1", "str2", "str3", "str4"); 

[DllImport(@"myproj.dll", EntryPoint = "somefunction")]
public static extern IntPtr SomeFunction([MarshalAs(UnmanagedType.LPWStr)]string jarg1, [MarshalAs(UnmanagedType.LPWStr)]string jarg2, [MarshalAs(UnmanagedType.LPWStr)]string jarg3, [MarshalAs(UnmanagedType.LPWStr)]string jarg4);

++

extern "C" __declspec(dllexport) void* __stdcall somefunction(wchar_t * jarg1, wchar_t * jarg2, wchar_t * jarg3, wchar_t * jarg4) 
{
//do some stuff with strings
}

SWIG, swig , .

++ , , .

+1

- , "" :

http://www.ondotnet.com/pub/a/dotnet/2004/03/29/mcpp_part3.html http://www.codeguru.com/cpp/cpp/cpp_managed/interop/article.php/c6867

None of these approaches use p / invoke, and this is the approach we use in the projects I'm working on, where we need to link the insanely old C ++ library - service.

0
source

Source: https://habr.com/ru/post/1707023/


All Articles