N
N
nait1233212016-06-20 00:12:06
C++ / C#
nait123321, 2016-06-20 00:12:06

Why is the DLL not being connected to the Visual Studio C++ project?

Hello, I created a DLL library according to the manual, and connected the files to the project using it, but #include doesn’t see them, it says it can’t open the file 8znsemgcUro.jpg
. What’s the problem?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Daniil Demidko, 2016-06-20
@nait123321

So, let's say we have a dynamic library MyDLL.dll with the following code

#include <windows.h>

int __declspec(dllexport) MyDLLSqr(const int n) {
    return n*n;
}

extern "C" bool __declspec(dllexport)
DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
    return true;
}

And our project with MyDLL.dll and main.cpp file and the following code:
#include <iostream>

extern "C" void __declspec(dllimport) MyDLLSqr (const int);

int main() {
    std::cout<< MyDLLSqr(4); // 4
}

That's pretty much how it all works.
How did you include the DLL?
Most likely in the missing DLL.h file there was something like
#pragma once

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif

extern "C" void DLL_EXPORT MyDLLSqr (const int);

For the convenience of using the functions declared in your DLL

P
Peter, 2016-06-20
@petermzg

#include
and linking are different things.
include is the path to the header files (*.h) - is specified in the project properties
. Linking is the path to the lib file - also in the properties, but in a different way.

D
Daemon23RUS, 2016-06-20
@Daemon23RUS

specify the correct path to DLL.h
It is likely that the file is either not readable or is in a different location

S
sitev_ru, 2016-06-20
@sitev_ru

Everything seems to be simple, it works for me: sitev.ru/post/77

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question