Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Query: Keyboard Hooks!

Query: Keyboard Hooks!

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabase
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nirav Doshi
    wrote on last edited by
    #1

    Hello, I have an application which hooks up the keyboard of a given process by injecting a DLL into the process. Now in that DLL, I have a (shared) char buffer which stores each keystroke. I am trying to get the buffer from my application, which is failing! Is there anything I am missing here? :~ : Here's how my code goes:

    ...
    #pragma data_seg(".WBA")
    char	g_chBuffer[0x101];
    #pragma data_seg()
    #pragma comment(linker, "/section:.WBA,rws")
    
    ...
    BOOL _declspec(dllexport) __stdcall GetAppBuffer(char *chfBufferOut)
    {
        if(chfBufferOut == NULL)
        {
    	return	FALSE;
        }
    
        char *pchBuffer = g_chBuffer;               // Here somehow, g_chBuffer is EMPTY! :((
    
        while((*chfBufferOut++ = *pchBuffer++) != 0);
    
        return	TRUE;
    }
    ...
    
    LRESULT _declspec(dllexport) CALLBACK GetKeyboardMsgs(int nCode, WPARAM wParam, LPARAM lParam)
    {
    ...
        static char *pchBuffer = g_chBuffer;
    ...
        ToAscii(wParam, nScan, chKeyState, &wTemp, 0);
        *pchBuffer++ = char(wTemp);                      // The buffer is fine here
    ...
    }
    

    In my application code, where I am calling the function GetAppBuffer():

    ...MyFunction()
    {
    ...
        static BOOL (__stdcall *fpGetAppBuffer)(char *) = NULL;
        if(m_hmodDLL != NULL)
        {
    	memset(chBuffer, STRING_TERMINATOR, 0x101);
    	fpGetAppBuffer = (BOOL (__stdcall *)(char *)) GetProcAddress(m_hmodDLL, "GetAppBuffer");
        }
    ...
        char chBuffer[0x101];
        memset(chBuffer, 0, 0x101);
        fpGetAppBuffer(chBuffer);            // It gets an empty chBuffer back! :(
    ....
    }
    

    Please reply with any of your comments/suggestions. Is there anything wrong, that I am doing here? Please write back even if you feel the question/code is not clear/insufficient. Thanks! Rgds, Nirav * Don't wish it was easier, wish you were better! *

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups