-1

I'm going to add a DLL which is made inside C# .net to a C++ project.

According to instructions inside some references like this, I should add its reference as below: Properties --> Common Properties --> Framework and References -->Add new Reference

In windows which titled Add Reference I should add DLL to my C++ project.

However this windows does not show any DLL files and have no options to browse DLL files.

Does anyone know how can I bring my custom DLL into this window?

enter image description here

P.S. Whole this story is about the requirement that I want to connect SQL Server inside a C++ project and I don't want to use C++ libraries. Instead I want to implement SQL related stuff inside a C# class library project and import it inside C++ project using C# project DLL. If you have any ideas about this I would be grateful if you share your idea or solution.

VSB
  • 9,825
  • 16
  • 72
  • 145
  • Here is the similar solved thread:[Using C# dll in C++ code](https://stackoverflow.com/questions/19144006/using-c-sharp-dll-in-c-code). – Minxin Yu - MSFT Oct 20 '21 at 08:08

1 Answers1

0

You cannot call managed (i.e. c# methods) from a native (i.e. c++) project without jumping thru some hoops. You have a few options:

  1. Make your project a c++/cli project, this will allow calling managed code directly. This would probably be the easiest, it should not be much more complex than turning on support for "common language runtime support" in the advanced project properties.
  2. Use a c++/cli adapter project between your native and managed code.
  3. Use some thirdparty software to generate native exported functions by some black magic.
  4. Rewrite your application in c#

For a c++/cli and c# projects you should have a "References" entry in your project that you can use to add assemblies to. I'm not sure if nuget works however, so you might need to managed the references manually.

JonasH
  • 28,608
  • 2
  • 10
  • 23