#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern"C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
#ifndef __MAIN_H__
#define __MAIN_H__ - these are pretty simple these are just header guards
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif - I don't know at all what's going on here,if defined BUILD_DLL?
#define __MAIN_H__ - these are pretty simple these are just header guards
Yes simple, but you're using a reserved identifier. Anything that starts with two underscores, or one underscore followed by an upper case letter is reserved for the implementation in any scope, and using a single leading underscore is also reserved for the implementation, if used within the global scope. Also remember that you must use distinct names in every file and MAIN_H may not be the best "name" for these header guards since it is a fairly common "name".
#endif - I don't know at all what's going on here,if defined BUILD_DLL?
Every #if must have a corresponding #endif.
I am doing it with codeblocks which is unusual
Why would you think using codeblocks to create a .dll or a static lib unusual?
Anything that starts with two underscores, or one underscore followed by an upper case letter is reserved for the implementation in any scope, and using a single leading underscore is also reserved for the implementation, if used within the global scope. Also remember that you must use distinct names in every file and MAIN_H may not be the best "name" for these header guards since it is a fairly common "name".
what is meant by reserved for the implementation? (in any scope, and global scope)
I have always noticed that most people create a static or dynamic library using visual studio
I have always noticed that most people create a static or dynamic library using visual studio
What about people that don't use visual studio, or gasp Windows?
what is meant by reserved for the implementation?
Exactly what it says it is reserved for the implementation, meaning you can't use that naming convention unless you are writing the compiler.
(in any scope, and global scope)
I assume you know how scope works, but as a refresher "any scope" means any where "global scope" means outside any functions, classes, structures or any other limited scope.
Visual Studio means you're using Microsoft's build system/compiler.
Code Blocks (by default, can be re-configured) means that you're using MinGW (GNU)'s build system/compiler. Which you want to use is just down to taste and requirements of your project -- preferably, a robust solution would be able to build on multiple systems and configurations, but this is not always reality.
what is meant by reserved for the implementation
Basically, it means that that identifier (macro, class name, variable name, etc.) could already be defined or in use by internal procedures. For example, "__cplusplus" is a macro. Defining your own macro called __cplusplus could cause problems with libraries and header files.
Example of use of __cplusplus (in C++ header file cstdint):
1 2 3
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
also why do we need the extern "C" in this particular case? I know extern "C" is used to stop function name mangling but why would we need it in this case?
also why do we need the extern "C" in this particular case? I know extern "C" is used to stop function name mangling but why would we need it in this case?
Do you know that every compiler can mangle names differently and that even the same compiler can mangle name differently depending on the version of the compiler?
Also that macro tells the compiler to use C calling semantics to allow C functions to call this function.
Why would you want to? It would only, at best, work with programs written with your particular compiler with everything compiled with the exact settings. A dll is meant to house code that can be shared by many different programs that were made by many different compilers. If, you don't care about sharing you might as well statically link instead of dynamic linking.