Thanks for prompt reply. This is the simplest code I posted.. Full source code of my dll is sent to you via email.
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "madCHook.h"
int (WINAPI *SHFileOperationANext) (LPSHFILEOPSTRUCTA lpFileOp);
int (WINAPI *SHFileOperationWNext) (LPSHFILEOPSTRUCTW lpFileOp);
int (WINAPI *ShellExecuteANext) (HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd);
int (WINAPI *ShellExecuteWNext) (HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);
int WINAPI SHFileOperationACallback(LPSHFILEOPSTRUCTA lpFileOp)
{
int res = SHFileOperationANext(lpFileOp);
// CreateProcess hooks are used very often, so to be sure we renew the hook
//RenewHook((PVOID*) &SHFileOperationANext);
return res;
}
int WINAPI SHFileOperationWCallback(LPSHFILEOPSTRUCTW lpFileOp)
{
//if (lpFileOp->fFlags != FO_MOVE || lpFileOp->fFlags != FO_COPY || lpFileOp->fFlags != FO_RENAME)
{
int rest1 = SHFileOperationWNext(lpFileOp);
return rest1;
}
}
//Shell Execute
int WINAPI ShellExecuteACallback(HWND hwnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, INT nShowCmd)
{
int result = ShellExecuteANext(hwnd,lpOperation,lpFile,lpParameters,lpDirectory,nShowCmd);
// CreateProcess hooks are used very often, so to be sure we renew the hook
RenewHook((PVOID*) &ShellExecuteANext);
return result;
}
int WINAPI ShellExecuteWCallback(HWND hwnd, LPCWSTR lpOperation, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
{
int result = ShellExecuteWNext(hwnd,lpOperation,lpFile,lpParameters,lpDirectory,nShowCmd);
// CreateProcess hooks are used very often, so to be sure we renew the hook
RenewHook((PVOID*) &ShellExecuteWNext);
return result;
}
BOOL WINAPI DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
//File Operation
HookAPI("shell32.dll", "SHFileOperationA", SHFileOperationACallback, (PVOID*) &SHFileOperationANext);
HookAPI("shell32.dll", "SHFileOperationW", SHFileOperationWCallback, (PVOID*) &SHFileOperationWNext);
//Shell Execute
HookAPI("shell32.dll", "ShellExecuteA", ShellExecuteACallback, (PVOID*) &ShellExecuteANext);
HookAPI("shell32.dll", "ShellExecuteW", ShellExecuteWCallback, (PVOID*) &ShellExecuteWNext);
}
return true;
}
regards
Sanjeev