Dll References in Visual C++

How to add a .dll reference to a project in Visual Studio

Copy the downloaded DLL file in a custom folder on your dev drive, then add the reference to your project using the Browse button in the Add Reference dialog.

Be sure that the new reference has the Copy Local = True.

The Add Reference dialog could be opened right-clicking on the References item in your project in Solution Explorer

UPDATE AFTER SOME YEARS
At the present time the best way to resolve all those problems is through the

Manage NuGet packages menu command of Visual Studio 2017/2019.

You can right click on the References node of your project and select that command. From the Browse tab search for the library you want to use in the NuGet repository, click on the item if found and then Install it. (Of course you need to have a package for that DLL and this is not guaranteed to exist)

Read about NuGet here

DLL References in Visual C++

You need to do a couple of things to use the library:

  1. Make sure that you have both the *.lib and the *.dll from the library you want to use. If you don't have the *.lib, skip #2

  2. Put a reference to the *.lib in the project. Right click the project name in the Solution Explorer and then select Configuration Properties->Linker->Input and put the name of the lib in the Additional Dependencies property.

  3. You have to make sure that VS can find the lib you just added so you have to go to the Tools menu and select Options... Then under Projects and Solutions select VC++ Directories,edit Library Directory option. From within here you can set the directory that contains your new lib by selecting the 'Library Files' in the 'Show Directories For:' drop down box. Just add the path to your lib file in the list of directories. If you dont have a lib you can omit this, but while your here you will also need to set the directory which contains your header files as well under the 'Include Files'. Do it the same way you added the lib.

After doing this you should be good to go and can use your library. If you dont have a lib file you can still use the dll by importing it yourself. During your applications startup you can explicitly load the dll by calling LoadLibrary (see: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx for more info)

Cheers!

EDIT

Remember to use #include < Foo.h > as opposed to #include "foo.h". The former searches the include path. The latter uses the local project files.

How to add a dll file into reference of Visual Studio properly?

As described in your question, this is the way you reference a class library or any other DLL-like reference.

Once compiled, your project copies its dependencies into its bin folder where you can find the referenced DLLs.

If you can't find the referenced DLL, set its Copy Local property to true.

Another way around is to set your Reference Paths. This will force, on compile-time, your project to update itself with DLLs from the specified reference paths.

The best practice was to create a Shared folder where all referenced libraries were in, so that you could write your reference paths once and for all per project.

Technologies being so great and vast on improvements, there's now NuGet Package Manager.

What is NuGet?

A collection of tools to automate the process of downloading, installing, upgrading, configuring, and removing packages from a VS Project.

How to use NuGet?

You may install it from within Visual Studio if it is not already installed, through the Extension Manager.

Otherwise, please visit the NuGet CodePlex Home Page.

Here's how Finding and Installing a NuGet Package Using the Package Manager Console has never been easier! =)

So when you open up an existing project, NuGet manages to get all the dependencies for you without any more effort from you. This should solve your concerns.

How to add DLL reference in Visual Studio Code

You need to add a reference to any .dll files in your csTemp.csproj file as such:

  <ItemGroup>
<Reference Include="OpenHardwareMonitorLib">
<HintPath>**path\to\your\dll**</HintPath>
</Reference>
</ItemGroup>

How to reference an assembly(*.dll) without visual studio?

Add the DLL reference into the csproj file.

Like (new csproj file format):

<ItemGroup>
<ProjectReference Include="..\..\*.dll" />
</ItemGroup>


Related Topics



Leave a reply



Submit