4

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 use 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()?

4 Answers4

3

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).

Arafangion
  • 11,517
  • 1
  • 40
  • 72
1

Is it managed C++ ? If so you can directly add a reference to the C# dll and use it.

ganeshran
  • 3,512
  • 7
  • 41
  • 69
  • I guess it isn't. My classes would have to had "__gc class A" right? I put "using ", and the CLR option and the compiler says: please specify the assembly search path using /AI or by setting the LIBPATH environment variable" I have the WordsExtraction.dll on my Debug folder – joaodavidmateus Nov 15 '10 at 10:56
1

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

Mor Shemesh
  • 2,689
  • 1
  • 24
  • 36
1

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

Nitin Bhide
  • 1,685
  • 14
  • 15