Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Short Summary of (some language) development in Visual Studio

Building and using DLL in Visual C++

  1. Create a library project to build DLL file. You will get .lib, .dll, and .h files.

  2. Create another project to use the DLL file. Then follow steps 2 to 6 on this project. You need to tell Visual Studio where to find the header files and library files via its Properties window.

  3. Go to project Properties > C/C++ > General and set Additional Include Directories to directory for header files (.h). (Or you can just copy the header files into your project.)

    If you build the project, you will get error LNK2019: unresolved external symbol because there is no library file yet.

  4. Go to project Properties > Linker > General and set Additional Library Directories to directory for library files (.lib). (Or you can just copy the library files into your project)

    Use $(IntDir) macro to replace "Debug" or "Release" string. Library files contain information about where the functions live in the DLL file. It's required for the linker, will be combined into .exe file when built.

  5. Go to project Properties > Linker > Input and set Additional Dependencies to library file name e.g. MathLibrary.lib.

    Step 4 and 5 are used together. If you build the project, it will succeed now. But you still won't be able to run the application because the DLL file is still missing. You will see a dialog box saying The code execution cannot proceed because xxxxx.dll was not found. Reinstalling the program may fix this problem.

  6. Go to project Properties > Build Events > Post-Build Event and set Command Line to

    xcopy /y /d "YourDLLProject\$(IntDir)YourDLLFile.dll" "$(OutDir)"

    to automatically copy the DLL file from the DLL project to your current project's output directory after every build.

    The DLL file does not need any extra path configuration. It just needs to be present close to the .exe file when it's executing. You can also manually copy the DLL file to the output directory and it will work the same like this step.

Read more from this tutorial:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment