Thread: HMODULE from current DLL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    137
    I'm not sure if I'm just imagining things but is this right?

    Code:
    HINSTANCE hinstDLL_;
    myClass myInstance( _hinstDLL );
    ★ Inferno provides Programming Tutorials in a variety of languages. Join our Programming Forums. ★

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    68
    Quote Originally Posted by execute View Post
    I'm not sure if I'm just imagining things but is this right?

    Code:
    HINSTANCE hinstDLL_;
    myClass myInstance( _hinstDLL );
    That was the only bit I typed out rather than copying & pasting, and I messed it up. The code actually reads
    Code:
    myClass myInstance( hinstDLL_ );
    If I do the following, it works perfectly. But I'd rather not hardcode the filename.
    Code:
    myClass myInstance( GetModuleHandle("myfile.dll") );

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    GetModuleHandleEx
    Code:
    HMODULE GetCurrentModuleHandle()
    {
        HMODULE hMod = NULL;
        GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
              reinterpret_cast<LPCWSTR>(&GetCurrentModuleHandle),
              &hMod);
         return hMod;
    }

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    68
    Quote Originally Posted by adeyblue View Post
    Thanks adeyblue. Currently my application runs on Win95+ (other than GetLastError which is 2k+), I'm not keen to introduce dependencies on this newer stuff unless I have to.

    Can you think of any other options? I'm still unsure why passing hinstDLL from dllMain isn't working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 08:39 AM
  3. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM