CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: working problem

  1. #1
    Join Date
    May 2012
    Posts
    14

    Exclamation working problem

    i made one program in c for keyboard hooking but its not working i made first one dll and after made one exe which load dll it is sample code

    /*THIS IS DLL CODE Replace "dll.h" with the name of your header */

    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include "key.h"

    HINSTANCE hinstance;
    HHOOK hook;
    LRESULT _declspec (dllexport)_stdcall KeyboardProc(int code,WPARAM wparam,LPARAM lparam)
    {
    if (code < 0)
    {
    return CallNextHookEx(hook,code,wparam,lparam);
    }
    if ((code == HC_ACTION)&&((wparam == WM_SYSKEYDOWN)||(wparam == WM_KEYDOWN)))
    {
    MessageBox(NULL,"TAB PRESS","WINDOWS",MB_OK);
    }
    return CallNextHookEx(hook,code,wparam,lparam);
    }
    BOOL _stdcall DllMain (HINSTANCE hInst /* Library instance handle. */ ,
    DWORD reason /* Reason this function is being called. */ ,
    LPVOID reserved /* Not used. */ )
    {
    hinstance = hInst;
    return TRUE;
    }
    BOOL _declspec (dllexport) installhook()
    {
    hook = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hinstance,0);
    }

    and its header file key.h

    #ifndef _DLL_H_
    #define _DLL_H_

    #if BUILDING_DLL
    # define DLLIMPORT __declspec (dllexport)
    #else /* Not BUILDING_DLL */
    # define DLLIMPORT __declspec (dllimport)
    #endif /* Not BUILDING_DLL */


    DLLIMPORT BOOL installhook();



    #endif /* _DLL_H_ */


    and after it my exe code

    #include<windows.h>
    #include<stdio.h>

    int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprvinstance,LPSTR cmdt,int cmdl)
    {
    HINSTANCE h;
    h = LoadLibrary("key.dll");
    BOOL (*p)();
    p = GetProcAddress(h,"installhook");
    (*p)();
    }

    give me right direction thx i only want when i press key my messagebox displyed

    thx

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

    Re: working problem

    Quote Originally Posted by raj874 View Post
    give me right direction thx i only want when i press key my messagebox displyed
    Did you debug your code?
    Did LoadLibrary succeed or fail?
    Did GetProcAddress succeed or fail?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2012
    Posts
    14

    Re: working problem

    Actully i didnt debug it but i checked it when i display the messagebox in installhook function in dll like it its works

    BOOL _declspec (dllexport) installhook()
    {
    hook = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,(HINSTANCE)hinstance,0);
    MessageBox(NULL,"ITS WORKS","WINDOWS",MB_OK);
    if (hook == NULL)
    {
    MessageBox(NULL,"HOOK NOT WORK","WINDOWS",MB_OK);
    }

    here i put one messagebox function and when i clicked on y exe that messagebox displayed mean getprocaddress works

  4. #4
    Join Date
    May 2012
    Posts
    14

    Re: working problem

    and also loadlibrary works fine sorry for double post this small matter

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

    Re: working problem

    Then try to debug your dll code!
    Victor Nijegorodov

  6. #6
    Join Date
    May 2012
    Posts
    14

    Re: working problem

    thx i solved problem

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

    Re: working problem

    Quote Originally Posted by raj874 View Post
    thx i solved problem
    Glad to know it!
    And what was the reason?
    Victor Nijegorodov

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