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 code, WPARAM wParam, LPARAM lParam);
//This function will get the procedure and set it to a variable
void DLLEXPORT SetHookCallback(SMPROC procaddr);
HRESULT DLLEXPORT MyhookProc(int code, WPARAM wParam, LPARAM 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 code, WPARAM wParam, LPARAM lParam)
{
//[COLOR=red]Now how do I call that stored procedure?[/COLOR]
return cbproc(code, wParam, lParam);
}




Reply With Quote