Advertisement Jump to content
Sign in to follow this  
Quat

dllexport global variable

This topic is 1739 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

This paper gives a way to force high performance rendering when working with optimus driver:

 

http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf

 

It says to use:

 

extern "C" {
    _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}

 

I'm not too familiar with dllexport.  Does this need to be in a header file or just any .cpp file (like app.cpp)?

 

 

Share this post


Link to post
Share on other sites
Advertisement

Doesn't matter, all this line means is your program is sayng to the outside world "hey, I'm exposing a variable NvOptimusEnablement with such and such value, if anyone cares", and presumably the optimus driver picks up on that. It doesn't matter where in your code you put it, as long as you don't export that variable twice (so perhaps it would be best to throw it in some special file like directives.cpp or whatever, where you can group all this stuff together, but if you have only one then app.cpp will do fine). If you intend to also use that variable from your own code (to do something special if high performance rendering is enabled, for instance) then it's slightly more complicated, but I doubt you need to do that.

 

Remember that header files are just pasted at #include directives, they're not special in any way.

Share this post


Link to post
Share on other sites

Usually you'll want to define a macro for doing this:

#ifdef COMPILING_DLL
#   define API __declspec(dllexport)
#else
#   define API __declspec(dllimport)
#endif

// NOTE: Might want to throw the above into an "export.h" file

extern "C" {
    API DWORD NvOptimusEnablement = 0x00000001;
}

Though you're probably better of defining it in the .cpp file as:

DWORD NvOptimusEnablement = 0x00000001;

And in your header file use:

extern "C" {
    API extern DWORD NvOptimusEnablement;
}

That way you're guaranteed that it will only be exported once.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!