Like Tree1Likes
  • 1 Post By Codeplug

CBT_CREATEWND lpcs->lpszName has invalid name?

This is a discussion on CBT_CREATEWND lpcs->lpszName has invalid name? within the Windows Programming forums, part of the Platform Specific Boards category; Hello all i tried to create a system wide hook (CBT) so that i can monitor processes and system events. ...

  1. #1
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493

    CBT_CREATEWND lpcs->lpszName has invalid name?

    Hello all
    i tried to create a system wide hook (CBT) so that i can monitor processes and system events. in the very beginning i am stuck!
    I cant get the name of the process! i dont know why i am getting this!
    I have also tried using:
    Code:
    if (IsWindowUnicode((HWND) wparam))  
          {
    
                    CBTHOOKCREATEW = (CBT_CREATEWNDW*) lparam;
                    CBTHOOKCREATESTRW = (CREATESTRUCTW*) lparam;
            }
    which failed again !
    Here is the actual code
    Code:
    LRESULT CALLBACK HookProcedure(int nCode, WPARAM wparam, LPARAM lparam)
    {
    
        if (nCode < 0) return CallNextHookEx(hookID, nCode, wparam, lparam);
    
        std::ofstream outfile;
        CBT_CREATEWND   *CBTHOOKCREATE;
        RECT            *CBTRECTPTR;
        RECT            CBTRECT;
        wstring         Message;
    
        CBTHOOKCREATE = (CBT_CREATEWND*) lparam;
        outfile.open(("d:\\test.txt"), std::ios_base::app);
    
        if (nCode >= 0) {
            switch (nCode)
            {
            case HCBT_CREATEWND:
                outfile << CBTHOOKCREATE->lpcs->lpszName << " Created! " << endl;
    
                break;
            case HCBT_DESTROYWND:
                outfile << "Destroyed!" << endl;
                break;
            default:
                break;
            }
        }
        outfile.close();
        return 0;
    }
    What am i doing wrong or missing here?
    Thanks in advance
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    Have you set a breakpoint and examined the contents of the structure in your debugger?

    And shy away from all caps for variable names.

    gg

  3. #3
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by Codeplug View Post
    Have you set a breakpoint and examined the contents of the structure in your debugger?

    And shy away from all caps for variable names.

    gg
    Thanks for the reply, but setting break points doesnt help! i tried setting couple of break points to check the values but it just doesnt get stopped! dont know why! maybe its because of being a system wide hook?!
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    Are you compiling with Unicode enabled (UNICODE/_UNICODE)?

    gg

  5. #5
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    493
    Quote Originally Posted by Codeplug View Post
    Are you compiling with Unicode enabled (UNICODE/_UNICODE)?

    gg
    Yes.
    by the way , it seems it doesnt give me the process names! only the windows titles right? how can i get the process names and get notified before they are executed so that if they are not in my list i terminate them? ( the sole reason for creating this system wide hook was for this very purpose!)
    Thanks in advance
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    Then "CBTHOOKCREATE->lpcs->lpszName" will be a wchar_t string.

    >> ... before they are executed ...
    Don't know about "before". You could use WMI, or you could use process enumeration API's and poll ever few seconds.

    Also found this: Hooking the native API and controlling process creation on a system-wide basis - CodeProject

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid comparison
    By Beowolf in forum C++ Programming
    Replies: 10
    Last Post: 12-02-2007, 04:44 PM
  2. Invalid Operands
    By chocobo59 in forum C Programming
    Replies: 6
    Last Post: 10-12-2007, 04:27 PM
  3. Invalid name?
    By rabbit in forum C++ Programming
    Replies: 4
    Last Post: 03-01-2006, 07:02 PM
  4. Why is this invalid?
    By sand_man in forum C Programming
    Replies: 1
    Last Post: 10-20-2004, 10:51 PM
  5. invalid conversion
    By black_sol in forum C++ Programming
    Replies: 3
    Last Post: 05-16-2004, 05:42 PM

Tags for this Thread


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