'How to use a Third-Party DLL in Visual Studio Code

I have a couple of header files that call functions from DLL files, and I was wondering how I could provide the link for the header files and DLL files to communicate in Visual Studio Code.

Let me know if you need me to elaborate on anything.



Solution 1:[1]

I believe you are looking to access the code defined in Dll. Generally all Dll projects we need to provide all the functions that needs to be exported. __dllexport__ After we build that DLL project .lib and .dll gets generated, based on all the functions exported.

So when you want to use the member function declared in some header and defined in DLL, you need to follow below steps.

  1. in Visual studio, add the .lib generated in Linker-Input-additional
  2. Dependencies add the path of linker->general->additional library directories
  3. Put the .dll in the path where your .exe is running

Solution 2:[2]

In Visual Studio code these are the steps what are needed to use DLL:

  1. Create lib file from DLL.

With MinGW it is something like this:

dlltool --input-def your_external_lib.def --dllname your_external_lib.dll --output-lib your_external_lib.lib
  1. modify the tasks.json

    {
    "version": "2.0.0",
    "tasks": [
        {
            "label": "your_project_name",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "-o",
                "main",
                "main.cpp",
                "-LC:\\YOUR_LIB_PATH"
                "-lyour_external_lib",
                "-Wall",
                "-Wextra"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
    }
    
  2. Add *.hpp and *.h files to your project and build!

Reference: http://www.mingw.org/wiki/Specify_the_libraries_for_the_linker_to_use

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Humble_Aspirant
Solution 2 D_Dog