I have some code in C# which I want to use in other project (coded in C++). From what I researched, I need to create a .lib but MSVS only creates .dll (I think..). I think is possible to u开发者_如何学Gose the .dll by using LoadLibrary() over C++ but seems not very friendly.
1 - Can I create the .lib in MSVS? If not, how can I create it.
2 - What is the best way to integrate the code? By the .lib or using .dll + LoadLibrary()?
The easiest option, honestly, is to use C++/CLI. That lets you use both object systems (.NET, and traditional C++ with its standard template library).
Is it managed C++ ? If so you can directly add a reference to the C# dll and use it.
What you need is a com compliant class in c#: http://en.allexperts.com/q/C-3307/2008/2/Using-C-class-C.htm http://blogs.msdn.com/b/deeptanshuv/archive/2005/06/26/432870.aspx
One possibility is to make your C# code Managed COM compliant. Then use the standard COM api's (QueryInterface etc) to call the C# COM code.
The codeproject sample may be useful http://www.codeproject.com/KB/cs/ManagedCOM.aspx
精彩评论