CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2010
    Posts
    38

    Obtain hinstance for hdc

    Hi
    Is there a way to obtain the hinstance of my program from the hdc value??
    Just poking around!

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Obtain hinstance for hdc

    Quote Originally Posted by vinayak4gargya View Post
    Is there a way to obtain the hinstance of my program from the hdc value??
    Sure, and you don't even need hdc for that.
    Your hInstance most likely is 0x00400000. Check in your debugger!
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Dec 2004
    Location
    Ann Arbor, MI
    Posts
    281

    Re: Obtain hinstance for hdc

    Yeah. Use ::WindowFromDC(HDC) to get the HWND, then use ::GetWindowLong(HWND, GWL_HINSTANCE) to get the instance handle.
    --EJMW

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Obtain hinstance for hdc

    Note also that ::WindowFromDC can return NULL if no window is associated with the specified DC.
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Obtain hinstance for hdc

    Quote Originally Posted by vinayak4gargya View Post
    Is there a way to obtain the hinstance of my program from the hdc value??
    No.
    hinstance & hdc = granny & machinegun
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Obtain hinstance for hdc

    VladimirF, is technically right -- a handle for HINSTANCE is most likely to be the same value for most 32-bit processes. It is actually passed into your application in the WinMain() function. Technically speaking the HINSTANCE is partially a rudiment that was carried over from 16-bit Windows and by itself could not be used to uniquely identify a process. Here's some information for you to understand what it is used for:
    http://blogs.msdn.com/b/oldnewthing/...18/409205.aspx

    So if you need to specifically link a resource to a certain process a better way would be to tie it up to a process ID.
    Last edited by ahmd; May 11th, 2011 at 12:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured