Jump to content
  • Advertisement
Sign in to follow this  
Azurecat

What does this file do? I see it all the time

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I like to take libraries and engines apart and try to figure out how they work. One of the things I do is to "trace" the headers to the program root, (if Certain.h includes a file called Stuff.h, I look in Stuff and find that it includes Things.h) and so on.

At the bottom of the chain is usually a file called Core.h, or Config.h, or something like that. The file is usually pretty short compared to others and has nothing but #ifdef and #define statements. Now I understand (simple) headers and how #ifdef works, and have used #defines pretty much for header guards up to this point. But I can't figure out what these files do or how they work.
Example: this is from api_core.h from Clanlib

#pragma once //I see this all the time, no idea what it does.

#ifdef CL_AP_DLL

#ifdef CL_CORE_EXPORT
#define CL_API_CORE __declspec(dllexport)
#define CL_API_CORE_STATIC

#else
#define CL_API_CORE __declspec(dllimport)
#define CL_API_CORE_STATIC __declspec(dllimport)

#endif

#else
#define CL_API_CORE
#define CL_API_CORE_STATIC

#endif

Normally I'd google this stuff, but in this case I wouldn't even know what to look for blink.gif. So what do files like this actually do? Comments, keywords, links, anything helps.

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

#pragma once
[/quote]
Its a non-standard but commonly available alternative to include guards. Google it.

__declspec(dllimport)
__declspec(dllexport)
[/quote]
It is some boilerplate for working with DLLs. You must explicitly list the functions/data you want to make available outside the DLL. Using this is an alternative to using Module Definition Files. Likewise, if you want the runtime to handle linking to the DLL (instead of manually calling GetProcAddress[/ulr]() or similar).

Google for "c++ dllimport" and "c++ dllexport". [url="http://msdn.microsoft.com/en-us/library/dabb5z75(v=vs.80).aspx"]__declspec
is more general than just DLLs. In practise, you'll mostly use __declspec with the dllimport/export attributes.

I got the links by Googling for "declspec", "dllimport c++" and "dllexport c++".

Share this post


Link to post
Share on other sites
Thanks, that was bugging me for a while now. I just assumed the _declspec was a user defined type/function. Gave me a ton of extra stuff to look into.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!