Jump to content

  • Log In with Google      Sign In   
  • Create Account

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: 422

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: 9305

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 TheComet   Crossbones+   -  Reputation: 1645

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