Results 1 to 2 of 2

Thread: Using a CALLBACK function

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Using a CALLBACK function

    I am trying to create a DLL that will host an application-defined procedure used set any type of hook. When you set a system-wide hook, you have to put the CALLBACK procedure in a DLL so this DLL will do the job. But I want to somehow alert the DLL caller about the message(s) that were recieved inside that CALLBACk procedure in the DLL. So my idea is to ask the caller for a CALLBACK function (same as WndProc if you're creating a window) that I'll call from inside the DLL with certain parameters so the caller knows which message was sent my the system. But the code to implement all this isn't working.
    Here it is:
    PHP Code:
    //************
    //myhook.h
    //***************

    #ifndef __MYHOOK_H__
    #define __MYHOOK_H__

    #include <windows.h>

    #ifdef _DLL_INTERNAL_
    #define DLLEXPORT __declspec(dllexport)
    #else
    #define DLLEXPORT __declspec(dllimport)
    #endif

    typedef LRESULT CALLBACK SMPROC(int codeWPARAM wParamLPARAM lParam);

    //This function will get the procedure and set it to a variable
    void DLLEXPORT SetHookCallback(SMPROC procaddr);
    HRESULT DLLEXPORT MyhookProc(int codeWPARAM wParamLPARAM lParam);
    #endif // __MYHOOK_H__ 
    PHP Code:
    #include <windows.h>

    #define _DLL_INTERNAL_
    #include "myhook.h"

    //A CALLBACK procedure that this dll will call whenever a message
    //is recieved inside the hook procedure
    SMPROC cbproc;

    void DLLEXPORT SetHookCallback(SMPROC procaddr) {
    //[COLOR=red]How do I store the CALLBACK procedure?[/COLOR]    
    strcpy((char*)&cbproc,(char*)&procaddr);
    }

    HRESULT DLLEXPORT MyhookProc(int codeWPARAM wParamLPARAM lParam)
    {
    //[COLOR=red]Now how do I call that stored procedure?[/COLOR]
    return cbproc(codewParamlParam);

    Baaaaaaaaah

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The call is correct.
    To store just do
    cbproc = procaddr;
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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