Jump to content

What the __declspec(dllexport/import) is used for?


Vida Marcell
 Share

Recommended Posts

I'm currently working with dlls in c++, and the first thing i noticed is this function __declspec(dllexport/import). There isn't too much explanations for it, but i think, the export if for making a function usable by other software that can acess the dll file, and the import is for the software to call a function from the dll? Am i correct?

Link to comment
Share on other sites

Correct, It's also best to have one Macro for both import and export and define a lib preprocessor define for the library's project like so. 

#if defined (INPUTSYSTEM_LIB)
    #define INPUTSYTEM_API DLL_EXPORT
    #define INPUTSYTEM_API_GLOBAL DLL_EXPORT_GLOBAL
#else
    #define INPUTSYTEM_API DLL_IMPORT
    #define INPUTSYTEM_API_GLOBAL DLL_IMPORT_GLOBAL
#endif

Then you make write your headers as so.

class INPUTSYTEM_API IInputDriver
{
public:
	IInputDriver() {};
    virtual ~IInputDriver() {};
};

INPUTSYTEM_API_GLOBAL void Init();

Working with DLLs can be a frustrating experience if your source tree isn't set up properly. You might want to consider public and private headers and expose the minimum to the other projects. 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...