Sign in to follow this  
Azurecat

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

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 [img]http://public.gamedev.net/public/style_emoticons/default/blink.gif[/img]. So what do files like this actually do? Comments, keywords, links, anything helps.

Thanks.

Share this post


Link to post
Share on other sites
[quote]
#pragma once
[/quote]
Its a non-standard but commonly available alternative to include guards. Google it.
[quote]
__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 [url="http://msdn.microsoft.com/en-us/library/28d6s79h(v=vs.80).aspx"]Module Definition Files[/url]. Likewise, if you want the runtime to handle linking to the DLL (instead of manually calling [url="http://msdn.microsoft.com/en-us/library/ms683212(v=vs.85).aspx"]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[/url] 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this