Anybody Know what this is doing?

1
2
3
4
5
6
7
8
9
#ifdef WIN32
#ifdef THU_EXPORTS
#define THU_API __declspec(dllexport)
#else
#define THU_API __declspec(dllimport)
#endif
#else
#define THU_API
#endif 


It's in a piece of code I am trying to understand however, It's not sinkin in lol....

I know define is to define a macro (function) or constant or a typedef but what is it doing here?

THU is a dynamic linked library or something in the profect I am trying to understand.

So another question I have is that a linked library can be an API correct?

Thanks for any hints.
Seems to be used in a/to use a shared object/dynamic library/whatever you call it (.so on POSIX systems, .dll on MS systems). POSIX doesn't require such redundancy, so it is defined empty if not compiled on a Win32 environment, in which case it uses some MS-specific declarations (I'd guess that one is used *in* the library, the other in the using code, but I'm not familiar with the Win API). Have a look in the msdn docs for what it does exactly.
Is this in a header file? - If so can you post the header file.
I have an idea what they are trying to do - but I just want to make sure.


edit..
(Which is pretty much along the line of what exception said - they are trying to make a common header file)

Last edited on
To understand better that think it to be like this:
1
2
3
4
5
6
7
8
9
#ifdef WIN32
        #ifdef THU_EXPORTS
                #define THU_API __declspec(dllexport)
        #else
                #define THU_API __declspec(dllimport)
        #endif
#else
        #define THU_API
#endif 


It defines in any case THU_API depending on what was previously declared it is set to __declspec(dllexport), __declspec(dllimport) or just nothing.
Usally this is used in Win32 to declare some functions is this way:
/*some other declarators*/ THU_API aFunction();
In order to have different compiled results based on what you defined before
Yes it is, it's part of a header file.....but then later down the file it declares new classes like this:
1
2
class THU_API newClassA {};
class THU_API newClassB{};


Here is the code again:

1
2
3
4
5
6
7
8
9
#ifdef WIN32
#ifdef THU_EXPORTS
#define THU_API __declspec(dllexport)
#else
#define THU_API __declspec(dllimport)
#endif
#else
#define THU_API
#endif 


the third and eighth lines of code - #define THU_API are greyed out in the header file display on my Visual Studio 2005. Whys that?

Why is there a statement to dllexport and dllimport? Isn't a dll just used for import purposes?

Topic archived. No new replies allowed.