Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a DLL in Visual Studio C++

I have a DLL that I've been using with no problem in Visual C# (simply adding the reference and using the namespace). Now I'm trying to learn C++, and I don't understand how you reference a namespace from a DLL. I can right-click on a project and select 'references' and from there click 'add new reference', but that just provides me with an empty 'projects' window. What am I missing?

like image 635
directedition Avatar asked Jan 24 '23 12:01

directedition


1 Answers

C++ is a lot different from C#/VB.Net when it comes to processing DLL references. In C# all that is needed to do a reference is a DLL because it contains metadata describing the structures that lay inside. The compiler can read this information such that they can be used from another project.

C++ does not have the concept of metadata in the DLL in the sense that C# does. Instead you must explicitly provide the metadata in the form of a header file. These files are included in your C++ project and then the DLL is delay loaded at runtime. You don't actually "add a reference" so to speak in C++ but include a header file instead.

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

using namespace SomeNamespace;
like image 160
JaredPar Avatar answered Jan 26 '23 03:01

JaredPar