Problems with hinstance.

This is a discussion on Problems with hinstance. within the Windows Programming forums, part of the Platform Specific Boards category; Hi. The hinstance of my program is automatically declared when WinMain is called. So it's local to WinMain. But what ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102

    Problems with hinstance.

    Hi.

    The hinstance of my program is automatically declared when WinMain is called. So it's local to WinMain. But what if I have to use it in another .cpp file globally?

    See what I have:
    Code:
    //engine.h
    class Engine
    {
            public: 
                 Engine(HINSTANCE hinstance)
                  {
                    //...
                    //needs hinstance
                    //...
                  }
    }
    //main.cpp
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE, LPSTR, int)
    {
    //...
    	Engine engine(hinstance); //inits program
    //...
    }
    
    //meshes.cpp
    class meshes : public Engine
    {
    public:
    	meshes(char* meshFileName) : Engine (hinstance); //what now? hinstance is not declared
    What would you recommend me to do in this situation?
    Thank you.

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    308
    Is windows header declared in engine.h nor meshess.cpp?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267
    Make a global HINSTANCE and assign it the value of the local hInstance

    OS: Windows 7, XUbuntu 11.10, Arch Linux
    IDE: CodeBlocks
    Compiler: GCC

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Another option is to use the return value from GetModuleHandle(0).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Or declare it and pass it...:
    Code:
    //meshes.cpp
    class meshes : public Engine
    {
    public:
    	meshes(char* meshFileName, HINSTANCE hinstance) : Engine (hinstance);
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Should you even have both an Engine instance and an instance of a class derived from Engine?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. resource problems
    By Dark_Phoenix in forum Windows Programming
    Replies: 2
    Last Post: 10-19-2008, 12:26 PM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. Problems with my DirectX program
    By fighter92 in forum Game Programming
    Replies: 1
    Last Post: 01-23-2007, 05:28 PM
  4. Compile Problems
    By Eber Kain in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 01:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21