c++ - Creating a class with static pointers to explicitly loaded DLL functions -


I have several examples of a DLLInterface class, but as each object is indicated for the same DLL function I be constant

The code below does not compile. (I have a reason for many examples with the same pointers, which does not explain the code below given below.)

  // Header file: typingfile (* DLLFunction) (); Class DLLInterface {Private: Stable HINSTANCE hinstDLL; Public: stable DLL function doo; DLLInterface () {if (! HinstDLL ||!) {HinstDLL = LoadLibrary ("DoubleThink.dll"); Do = (DLF) GetProcAddress (hinstDLL, "two"); }}};  

I also need all the code contained in this header file. (I know that I can compile it by adding the given statement to the EXP file in the EXE but I need to avoid doing this.

Histones DLLInterface :: hinstDLL = 0;

Thank you!

I can think that there is something that Using templates is the idea that you include the class in the static data in a template class, and then it will give some special By type:

  template  class DLLInterfaceImpl; {private: static histine hinstDLL; public: static DLLFunction Do;}; template & lt; class T & Gt; HINSTANCE DllInterfaceImpl & lt; T & gt; :: hInstDLL; Template & lt; class T & gt; DLLFunction DllInterfaceImpl & lt; T & gt;: Dll; Class DllInterface: Public DllInterfaceImpl & lt; int & gt; {} ;  

Because DllInterfaceImpl is a template, you can place your static definitions in the header file, and the compiler will do some "tricks" so that many definitions fail the relationship One does not cause.


Comments