CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2004
    Posts
    244

    Check if LPCWSTR is an atom or not?

    I have a hook on the function CreateWindowExW. I tried to call wcscmp on the lpClassName parameter to see what class I am created, but when lpClassName is an atom it crashes. How can I check whether or not lpClassName is an atom or LPCWSTR?

    Thanks,
    inbugable

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Check if LPCWSTR is an atom or not?

    From MSDN on CreateWindowEx:
    lpClassName
    [in] Long pointer to a null-terminated string or an integer atom. If this parameter is an atom, it must be a global atom created by a previous call to the RegisterClass function. The atom, a 16-bit value less than 0xC000, must be in the low-order word of lpClassName; the high-order word must be zero.
    Maybe you can make a check to see if the lpClassName argument meets the criteria of an atom.

    - petter
    Last edited by wildfrog; May 19th, 2007 at 05:59 PM. Reason: typo in red...

  3. #3
    Join Date
    Sep 2004
    Posts
    244

    Re: Check if LPCWSTR is an atom or not?

    Thanks but its not working. Could you post some sample code plz?

    Thanks

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

    Re: Check if LPCWSTR is an atom or not?

    Quote Originally Posted by inbugable
    Thanks but its not working.
    First, please show us what did you try and it's not working.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  5. #5
    Join Date
    Sep 2004
    Posts
    244

    Re: Check if LPCWSTR is an atom or not?

    I tried:

    if(HIWORD((ATOM)lpClassName) == 0){

    and

    if((ATOM)lpClassName < 0xC000){

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Check if LPCWSTR is an atom or not?

    Wildfrogs posting is correct so....

    1) What is the actual 32 bit hex value you are testing (a debugger and a breakpoint makes this trivial).

    2) Why do you think the value is (or is not) an Atom. What is the code that generates the value? [please dont forget code tags - like you forgot them in your previous post !]
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

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

    Re: Check if LPCWSTR is an atom or not?

    Just to quote this
    Quote Originally Posted by inbugable
    if(HIWORD((ATOM)lpClassName) == 0)
    As already said above, ATOM is a 16-bit (WORD) value so
    Code:
    HIWORD((ATOM)someting)
    will be always 0.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  8. #8
    Join Date
    Sep 2004
    Posts
    244

    Re: Check if LPCWSTR is an atom or not?

    1) The class is 0xC038 but casted to a LPCWSTR
    2) I dont know the code that generates the value because im running injected code in another process

  9. #9
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Check if LPCWSTR is an atom or not?

    I'm sorry, the quote from MSDN was for Windows CE. I'll try again:
    lpClassName
    [in] Pointer to a null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero. If lpClassName is a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window. The class name can also be any of the predefined system class names.
    What if you try this:
    Code:
    if (HIWORD(lpClassName) == 0)
    {
        // atom
    } else
    {
        // class name
    }
    - petter

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