Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


dllexport global variable


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   -  Reputation: 424

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

Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 10939

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   Crossbones+   -  Reputation: 1911

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.


YOUR_OPINION >/dev/null




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.



PARTNERS