Link an external custom DLL


Hi all,
I'm new to C++ and visual studio.
I started a new empty c++ project with a class that has an exported function:
1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once
#ifdef DEBUGMESSENGER_EXPORTS
#define MESSENGER_API __declspec(dllexport) 
#else
#define MESSENGER_API __declspec(dllimport) 
#endif

namespace DebugMessenger {
    class Messenger {
    public:
        static MESSENGER_API void debugMessage();
    };
}

I compiled the project and got a dll + lib files.
I also created a cpp file with the function implementation.
Next, I created a new project (in another solution), and I linked the DLL. I tried 2 methods:
1. right click on the client project (on solution explorer) -> properties -> Configuration properties -> Linker -> Input -> Adding the .lib file to the Additional Dependencies.
2. right click on the client project (on solution explorer) -> properties -> Configuration properties -> C/C++ -> General -> Adding the folder where the lib/dll files are located to the Additional include directories.

both of them were not helpful, and I can't use my dll exported function. Any idea what I'm missing?
closed account (E0p9LyTq)
Creating and using DLLs in the Visual Studio IDE is easier if you create separate projects in the same solution. After all, your app is dependent on the DLL,

For VS 2015:

Walkthrough: Creating and Using a Dynamic Link Library (C++)
https://msdn.microsoft.com/en-us/library/ms235636.aspx

There are walkthroughs for other VS versions available as well.

If you ever want to create a custom static library:

Walkthrough: Creating and Using a Static Library
https://msdn.microsoft.com/en-us/library/ms235627.aspx
Topic archived. No new replies allowed.