Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

dllexport global variable

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Quat   Members   

567
Like
1Likes
Like

Posted 17 April 2014 - 10:57 AM

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)?

 

 


-----Quat

#2 Bacterius   Members   

13164
Like
1Likes
Like

Posted 17 April 2014 - 11:08 AM

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.


“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


#3 TheComet   Members   

3858
Like
1Likes
Like

Posted 17 April 2014 - 11:11 AM

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.


"I would try to find halo source code by bungie best fps engine ever created, u see why call of duty loses speed due to its detail." -- GettingNifty




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.