Is it possible to take a static library written in C++ and somehow integrate it into a .NET process in a way that the .NET process will be integrated with the lib into one exe file?
What I mean is that I know I can invoke a c++ DLL from within a C# process but the user will still have to have the C++ DLL, but is it possible to use a lib instead of a DLL?(this way the user won’t even know that the exe uses my library).
and if it is possible, how?
Is it possible to take a static library written in C++ and somehow integrate
Share
Unique among other managed languages, C++ allows for mixed mode – a combination of managed (C++/CLI) and native C++ within the same compilation unit (dll/exe/lib), with calls back and forth. Maybe you can leverage that, create a kind of a glue layer. I’ve never tried though.
The key is the /clr compiler switch – you apply it to some files in the project but not others. Then you create some classes/functions as managed. The unmanaged bits can see them and call them, and vice versa. Passing primitive types around is done transparently, for strings there’s some marshaling trickery. I’ll be able to post more on Monday.
EDIT: seems like some deep magic would be required. Not on the mixed C++ side – on the linking the result to C# side. The Visual Studio IDE does not readily support the scenario, you see. Chances are, the regular build process won’t be of any use.
EDIT2: you can compile your C++ bits to a .netmodule by specifying a /LN command line option to the compiler and /NOASSEMBLY to a linker. Now, to link that to the C# exe…