首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

madCHook.dll 声明的转化 请高手都进来看,不是一般的有关问题

2012-03-13 
madCHook.dll 声明的转化 请高手都进来看,不是一般的问题!以下是函数在c的声明#includewindows.h#includ

madCHook.dll 声明的转化 请高手都进来看,不是一般的问题!
以下是函数在c的声明
#include   <windows.h>
#include   "madCHook.h "
UINT   (WINAPI   *WinExecNextHook)(LPCSTR   lpCmdLine,   UINT   uCmdShow);//这句是声明指针变量WinExecNextHook
UINT   WINAPI   WinExecHookProc(LPCSTR   lpCmdLine,   UINT   uCmdShow)//定义一个新的函数代替回调函数就是代替WinExecNextHook保存的地址处的函数
{
    if   (MessageBox(0,   lpCmdLine,   "Execute? ",   MB_YESNO   |   MB_ICONQUESTION)   ==   IDYES)
        return   WinExecNextHook(lpCmdLine,   uCmdShow);//如果是调用原来的回调函数
    else
        return   ERROR_ACCESS_DENIED;//否返回拒绝访问
}
int   WINAPI   WinMain(HINSTANCE   hInstance,
                                      HINSTANCE   hPrevInstance,
                                      LPSTR           lpCmdLine,
                                      int               nCmdShow)
{
    InitializeMadCHook();//初始化钩子
    //用新的回调函数代替原来的,并保存系统原来函数地址
    HookAPI( "kernel32.dll ",   "WinExec ",   WinExecHookProc,   (PVOID*)   &WinExecNextHook);
    WinExec( "notepad.exe ",   SW_SHOWNORMAL);//运行记事本,将会调用新的函数WinExecHookProc
  UnhookAPI((PVOID*)   &WinExecNextHook);//该回原来的设置
  FinalizeMadCHook();//钩子释放处理
    return   true;//返回系统应该是return   0比较好吧??
}


#include   "madCHook.h "
把madCHook.h代码贴上来
头文件太大了,贴不出来,不过与HOOKAPI相关的我找出来贴到下面了:
madCHookApi(BOOL)   HookAPI(
    LPCSTR   pszModule,
    LPCSTR   pszFuncName,
    PVOID     pCallbackFunc,
    PVOID     *pNextHook,
    #ifdef   __cplusplus
        DWORD     dwFlags   =   0
    #else
        DWORD     dwFlags
    #endif
);

以上代码在vb中应该如何声明,和调用呢,请会的高人帮忙转化一下,要带个调用例子的,代码调试成功报酬可商议~~谢谢了startbin#126.com

[解决办法]
首先 WinExecNextHook 不是一个输出函数,只是一个指向原函数的指针

===================================

那就直接声明成long型变量,然后用 addressof 一个函数地址赋值给它
还有一个问题就是,这个东西即使翻译成vb好像也无法正常工作,我以前也做过,不知道是什么问题,最后我是用C++再包了一层再给vb调用的,很郁闷


======================================================

Public Declare Function GetCurrentSessionId Lib "madCHook.dll " () As Long
Public Declare Function AmUsingInputDesktop Lib "madCHook.dll " () As Long

'CreateIpcQueue( _
LPCSTR pIpc, _
PIPC_CALLBACK_ROUTINE pCallback _
);
Public Declare Function CreateIpcQueue Lib "madCHook.dll " (ByVal pIpc As String, ByVal pCallback As Long) As Long

'InjectLibraryA( _
DWORD dwProcessHandleOrSpecialFlags, _
LPCSTR pLibFileName, _
#ifdef __cplusplus _
DWORD dwTimeOut = 7000 _
#Else _
DWORD dwTimeOut _
#End If _
);
Public Declare Function InjectLibraryAnsi Lib "madCHook.dll " Alias "InjectLibraryA " _


(ByVal dwProcessHandleOrSpecialFlags As Long, _
ByVal pLibFileName As String, _
ByVal dwTimeOut As Long) As Long

Public Declare Function InjectLibraryUnicode Lib "madCHook.dll " Alias "InjectLibraryW " _
(ByVal dwProcessHandleOrSpecialFlags As Long, _
ByVal pLibFileName As String, _
ByVal dwTimeOut As Long) As Long

Public Declare Function UnInjectLibraryAnsi Lib "madCHook.dll " Alias "UninjectLibraryA " _
(ByVal dwProcessHandleOrSpecialFlags As Long, _
ByVal pLibFileName As String, _
ByVal dwTimeOut As Long) As Long

Public Declare Function UnInjectLibraryUnicode Lib "madCHook.dll " Alias "UninjectLibraryW " _
(ByVal dwProcessHandleOrSpecialFlags As Long, _
ByVal pLibFileName As String, _
ByVal dwTimeOut As Long) As Long

'madCHookApi(BOOL) SendIpcMessage( _
LPCSTR pIpc, _
PVOID pMessageBuf, _
DWORD dwMessageLen, _
#ifdef __cplusplus _
PVOID pAnswerBuf = NULL, _
DWORD dwAnswerLen = 0, _
DWORD dwAnswerTimeOut = INFINITE, _
BOOL bHandleMessage = True _
#Else _
PVOID pAnswerBuf, _
DWORD dwAnswerLen, _
DWORD dwAnswerTimeOut, _
BOOL bHandleMessage _
#End If _
);

Public Declare Function SendIpcMessage Lib "madCHook.dll " ( _
ByVal pIpc As String, _
ByRef pMessageBuf As TDllInjectRequest, _
ByVal dwMessageLen As Long, _
ByVal pAnswerBuf As Long, _
ByVal dwAnswerLen As Long, _
ByVal dwAnswerTimeOut As Long, _
ByVal bHandleMessage As Long) As Long


'madCHookApi(BOOL) HookAPI( _
LPCSTR pszModule, _
LPCSTR pszFuncName, _
PVOID pCallbackFunc, _
PVOID *pNextHook, _
#ifdef __cplusplus _
DWORD dwFlags = 0 _
#Else _
DWORD dwFlags _
#End If _
);

Public Declare Function HookAPI Lib "madCHook.dll " ( _
ByVal pszModule As String, _
ByVal pszFuncName As String, _
ByVal pCallbackFunc As Long, _
ByVal pNexthook As Long, _
ByVal dwFlags As Long) As Long


'madCHookApi(BOOL) UnhookAPI ( PVOID *pNextHook );
Public Declare Function UnhookAPI Lib "madCHook.dll " (ByVal pNexthook As Long) As Long

'madCHookApi(VOID) AutoUnhook (HINSTANCE hinstDLL);
Public Declare Sub AutoUnhook Lib "madCHook.dll " (ByVal hinstDLL As Long)


Public Declare Sub SetLastError Lib "kernel32 " (ByVal dwErrCode As Long)
Public Declare Sub CopyMemory Lib "kernel32 " Alias "RtlMoveMemory " (Destination As Any, Source As Any, ByVal Length As Long)




'typedef struct
'// this is the information record which we send to our injection service
'TDllInjectRequest { _
BOOL bInject; _
DWORD dwTimeOut; _
DWORD dwSession; _
} *PDllInjectRequest;

Public Type TDllInjectRequest
bInject As Long
dwTimeOut As Long
dwSession As Long
End Type


'typedef struct _
// this is the information record which our dll sends us _
TTerminationRequest { _
BYTE bSystem; _
CHAR szProcess1 [MAX_PATH + 1]; _
CHAR szProcess2 [MAX_PATH + 1]; _
} *PTerminationRequest;

Public Type TTerminationRequest
bSystem As Byte
szProcess1 As String * 261
szProcess2 As String * 261
End Type

Public Const CURRENT_SESSION As Long = &HFFFFFFEC
Public Const SYSTEM_PROCESSES As Long = &H10
Public Const INFINITE As Long = &HFFFFFFFF
Public Const ERROR_ACCESS_DENIED As Long = 5

热点排行