Using DLL in Visual Studio C ++

I have a DLL that I used without problems in Visual C # (just adding a link and using a namespace). Now I am trying to learn C ++, and I do not understand how you refer to the namespace from the DLL. I can right-click on the project and select “links”, and from there click “add new link”, but this just gives me an empty “projects” window. What am I missing?

+4
source share
3 answers

C ++ is a lot different than C # / VB.Net when it comes to handling DLL links. In C #, all that is needed to execute a link is a DLL, because it contains metadata describing the structures that lie inside. The compiler can read this information so that it can be used from another project.

C ++ has no concept of metadata in a DLL in the sense that C # does. Instead, you should explicitly provide metadata in the form of a header file. These files are included in your C ++ project, and then the DLL is delayed at runtime. You actually do not add a link, so to speak, in C ++, but instead include a header file.

Once the header file is included, you can access the namespace by including it in your CPP files

using namespace SomeNamespace; 
+6
source

First of all, if you are trying to use the same DLL that you used in your C # application, if you use pure native C ++, it is not easy to make calls to this DLL. The problem is that the DLL that you reference in C # uses the .NET platform to execute (it is a “managed” DLL, since all assemblies are C #, VB.NET, and C ++ / CLI). There is an easy way to refer to “managed” code from C ++, namely to create a managed C ++ project (AKA C ++ / CLI) (select from the “CLR” section in the C ++ Project Wizard in Visual Studio). Otherwise, the only way to access the managed DLL is to provide it with COM and use COM to access the object.

+3
source

EDIT: the previous answer will be more useful if you use unmanaged C ++; I assumed because of the C # link that you targeted managed C ++ to.

The "Add Link" dialog should have a number of tabs - "Projects" lists the projects in the current solution; .NET lists the libraries installed in the GAC, and "Browse" allows you to find the DLL yourself.

If you just want to add a link to the DLL, you can do this using the Browse. If you have a source at the output of the project, add the project to the solution and it will appear on the Projects tab.

If this does not help, which version of Visual Studio are you using, and where / what is the DLL that you want to use?

0
source

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


All Articles