Hi, I am currently reading about how to make DLLs and I am seriously struggling to understand what's going on. So I will ask each question I have and hope that any of you can help me. I could just accept everything and copy-paste but that will just build up frustration where I keep asking what's going on like now.
The code:
dllFile.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef _DLL_TUTORIAL_H_
#define _DLL_TUTORIAL_H_
#include <iostream>
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
extern "C"
{
DECLDIR int Add( int a, int b );
DECLDIR void Function( void );
}
#endif
|
dllFile.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include "DLL_Tutorial.h"
#define DLL_EXPORT
extern "C"
{
DECLDIR int Add( int a, int b )
{
return( a + b );
}
DECLDIR void Function( void )
{
std::cout << "DLL Called!" << std::endl;
}
}
|
I will make bullet points for each question.
*1: What does "#if defined DLL_EXPORT" do? Why is it needed?
*2: When will DECLDIR be replaced with "__declspec(dllexport)"?
*3: When will DECLDIR be replaced with "__declspec(dllimport)"?
*4: What does "#define DLL_EXPORT" do? Why is it needed?
*5: I still do not understand the #define directive. When I read about it, they say that #define will replace the identifier with a replacement.
But how does it work in a header guard? There you only have for
example: "#define FILE_H (replacement missing?)" - the identifier FILE_H, but we do NOT give it a replacement.
I am sorry if I give you too many questions. But as a beginner it felt very hard ot understand all of this at once.
Thanks for all help!
Best regards, Zerpent :).