Thread: GetModuleHandle

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    GetModuleHandle

    I know that when you are not working with any DLL's that GetModuleHandle(0) is a perfect way to retrive hInstance and not have to make it global. However, in the project I'm working on now I am using DLL's and I'm wondering if it is okay to use GetModuleHandle(0) here and if not what is another possibility?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Depends on which handle you want. If you want the DLL's handle then you'll need to pass the DDL's name.

    gg

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If working on a DLL you could store the hInstance from DllMain in a global variable. Other methods are discussed here. By my reading of the documentation the following code should also work. By the complicated workarounds posted on the web I suspect it doesn't, but it's worth a try.
    Code:
    GetModuleFileName(NULL, szModule, MAX_PATH);
    GetModuleHandle(szModule);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find Injected DLLs In A Process?
    By pobri19 in forum Windows Programming
    Replies: 35
    Last Post: 02-06-2010, 09:53 AM
  2. Why doesn't this example work for me?
    By xixpsychoxix in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2009, 08:25 PM
  3. Button positioning
    By Lionmane in forum Windows Programming
    Replies: 76
    Last Post: 10-21-2005, 05:22 AM
  4. GetModuleHandle (NULL) vs hInstance
    By Lionmane in forum Windows Programming
    Replies: 2
    Last Post: 10-05-2005, 01:33 AM