全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2059
推到 Plurk!
推到 Facebook!

請問這段代碼的用法與vb改寫

尚未結案
hotswin
中階會員


發表:72
回覆:92
積分:52
註冊:2003-11-06

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-22 17:33:30 IP:220.134.xxx.xxx 未訂閱
@InstallHook := GetProcAddress(ModuleHandle, 'InstallHook'); @UnHook := GetProcAddress(ModuleHandle, 'UnHook'); 啟動winsock hook時,以上這2行是什麼意思呢??跟hook鍵盤用法不一樣呢 我想把它改成Vb的用法,請教怎做呢 以下是完整的代碼了
procedure TForm1.Button1Click(Sender: TObject);
var
ModuleHandle: THandle;
TmpWndHandle: THandle;
begin
TmpWndHandle := 0;
TmpWndHandle := FindWindow(nil, '目标窗口的标题');
if not isWindow(TmpWndHandle) then
begin
MessageBox(self.Handle, '没有找到窗口', '!!!', MB_OK);
exit;
end;
ModuleHandle := LoadLibrary('Hook.dll');
@InstallHook := GetProcAddress(ModuleHandle, 'InstallHook');
@UnHook := GetProcAddress(ModuleHandle, 'UnHook');
if InstallHook(FindWindow(nil, 'Untitled')) then
ShowMessage('Hook OK');
end;
------
xinjier禮品贈品
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-23 12:32:27 IP:210.69.xxx.xxx 未訂閱
詳細說明如下 (這邊的人安裝的是 Delphi 或 BCB, 幫您改寫成 VB 用有點困難)    
procedure TForm1.Button1Click(Sender: TObject);
var
// THandle is the type for handles to operating system resources.
  ModuleHandle: THandle;
  TmpWndHandle: THandle;
begin
  TmpWndHandle := 0;
  TmpWndHandle := FindWindow(nil, '目標視窗的標題');
  if not isWindow(TmpWndHandle) then          // isWindow 解釋如下
  begin
    MessageBox(self.Handle, '沒有找到視窗', '!!!', MB_OK);   // MessageBox 解釋如下
    exit;
  end;
  ModuleHandle := LoadLibrary('Hook.dll');
  @InstallHook := GetProcAddress(ModuleHandle, 'InstallHook');
  @UnHook := GetProcAddress(ModuleHandle, 'UnHook');      // InstallHook 不是 Win32 SDK 或 Delphi 的 API
  // 或者是較新的 API, Delphi7 的 Win32 API Help 中沒有紀錄
  if InstallHook(FindWindow(nil, 'Untitled')) then
    ShowMessage('Hook OK');
  end;
{***********************************************************} { The IsWindow function determines whether the specified window handle identifies an existing window. BOOL IsWindow( HWND hWnd // handle of window ); Parameters hWnd Specifies the window handle. Return Values If the window handle identifies an existing window, the return value is nonzero. If the window handle does not identify an existing window, the return value is zero. } {***********************************************************} { MessageBox : Displays a specified message to the user. Delphi syntax: function MessageBox(const Text, Caption: PChar; Flags: Longint = MB_OK): Integer; C syntax: int __fastcall MessageBox(const char * Text, const char * Caption, int Flags = MB_OK); Description Use MessageBox to display a generic dialog box a message and one or more buttons. Caption is the caption of the dialog box and is optional. MessageBox is an encapsulation of the Windows API MessageBox function. TApplication? encapsulation of MessageBox automatically supplies the missing window handle parameter needed for the Windows API function. The value of the Text parameter is the message, which can be longer than 255 characters if necessary. Long messages are automatically wrapped in the message box. The value of the Caption parameter is the caption that appears in the title bar of the dialog box. Captions can be longer than 255 characters, but don't wrap. A long caption results in a wide message box. The Flags parameter specifies what buttons appear on the message box and the behavior (possible return values). The following table lists the possible values. These values can be combined to obtain the desired effect. Value Meaning MB_ABORTRETRYIGNORE The message box contains three push buttons: Abort, Retry, and Ignore. MB_OK The message box contains one push button: OK. This is the default. MB_OKCANCEL The message box contains two push buttons: OK and Cancel. MB_RETRYCANCEL The message box contains two push buttons: Retry and Cancel. MB_YESNO The message box contains two push buttons: Yes and No. MB_YESNOCANCEL The message box contains three push buttons: Yes, No, and Cancel. MessageBox returns 0 if there isn急 enough memory to create the message box. Otherwise it returns one of the following values: Value Numeric value Meaning IDOK 1 The user chose the OK button. IDCANCEL 2 The user chose the Cancel button. IDABORT 3 The user chose the Abort button. IDRETRY 4 The user chose the Retry button. IDIGNORE 5 The user chose the Ignore button. IDYES 6 The user chose the Yes button. IDNO 7 The user chose the No button. } {***********************************************************} { The LoadLibrary function maps the specified executable module into the address space of the calling process. HINSTANCE LoadLibrary( LPCTSTR lpLibFileName // address of filename of executable module ); Parameters lpLibFileName Points to a null-terminated string that names the executable module (either a .DLL or .EXE file). The name specified is the filename of the module and is not related to the name stored in the library module itself, as specified by the LIBRARY keyword in the module-definition (.DEF) file. If the string specifies a path but the file does not exist in the specified directory, the function fails. If a path is not specified and the filename extension is omitted, the default library extension .DLL is appended. However, the filename string can include a trailing point character (.) to indicate that the module name has no extension. When no path is specified, the function searches for the file in the following sequence: 1. The directory from which the application loaded. 2. The current directory. 3. Windows 95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory. Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32. 4. Windows NT: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM. 5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 6. The directories that are listed in the PATH environment variable. The first directory searched is the one directory containing the image file used to create the calling process (for more information, see the CreateProcess function). Doing this allows private dynamic-link library (DLL) files associated with a process to be found without adding the process's installed directory to the PATH environment variable. Once the function obtains a fully qualified path to a library module file, the path is compared (case independently) to the full paths of library modules currently loaded into the calling process. These libraries include those loaded when the process was starting up as well as those previously loaded by LoadLibrary but not unloaded by FreeLibrary. If the path matches the path of an already loaded module, the function just increments the reference count for the module and returns the module handle for that library. Return Values If the function succeeds, the return value is a handle to the module. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Remarks LoadLibrary can be used to map a DLL module and return a handle that can be used in GetProcAddress to get the address of a DLL function. LoadLibrary can also be used to map other executable modules. For example, the function can specify an .EXE file to get a handle that can be used in FindResource or LoadResource. Module handles are not global or inheritable. A call to LoadLibrary by one process does not produce a handle that another process can use ?for example, in calling GetProcAddress. The other process must make its own call to LoadLibrary for the module before calling GetProcAddress. If the module is a DLL not already mapped for the calling process, the system calls the DLL's DllEntryPoint function with the DLL_PROCESS_ATTACH value. If the DLL's entry-point function does not return TRUE, LoadLibrary fails and returns NULL. Windows 95: If you are using LoadLibrary to load a module that contains a resource whose numeric identifier is greater than 0x7FFF, LoadLibrary fails. See Also DllEntryPoint, FindResource, FreeLibrary, GetProcAddress, GetSystemDirectory, GetWindowsDirectory, LoadResource } {***********************************************************} { The GetProcAddress function returns the address of the specified exported dynamic-link library (DLL) function. FARPROC GetProcAddress( HMODULE hModule, // handle to DLL module LPCSTR lpProcName // name of function ); Parameters hModule Identifies the DLL module that contains the function. The LoadLibrary or GetModuleHandle function returns this handle. lpProcName Points to a null-terminated string containing the function name, or specifies the function's ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero. Return Values If the function succeeds, the return value is the address of the DLL's exported function. If the function fails, the return value is NULL. To get extended error information, call GetLastError. Remarks The GetProcAddress function is used to retrieve addresses of exported functions in DLLs. The spelling and case of the function name pointed to by lpProcName must be identical to that in the EXPORTS statement of the source DLL's module-definition (.DEF) file. The lpProcName parameter can identify the DLL function by specifying an ordinal value associated with the function in the EXPORTS statement. GetProcAddress verifies that the specified ordinal is in the range 1 through the highest ordinal value exported in the .DEF file. The function then uses the ordinal as an index to read the function's address from a function table. If the .DEF file does not number the functions consecutively from 1 to N (where N is the number of exported functions), an error can occur where GetProcAddress returns an invalid, non-NULL address, even though there is no function with the specified ordinal. In cases where the function may not exist, the function should be specified by name rather than by ordinal value. See Also FreeLibrary, GetModuleHandle, LoadLibrary } {***********************************************************} {The FindWindow function retrieves the handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. HWND FindWindow( LPCTSTR lpClassName, // pointer to class name LPCTSTR lpWindowName // pointer to window name ); Parameters lpClassName Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero. lpWindowName Points to a null-terminated string that specifies the window name (the window's title). If this parameter is NULL, all window names match. Return Values If the function succeeds, the return value is the handle to the window that has the specified class name and window name. If the function fails, the return value is NULL. To get extended error information, call GetLastError. See Also EnumWindows, FindWindowEx, GetClassName, GlobalAddAtom } {***********************************************************} { Displays a message box with an OK button. Unit Dialogsor QDialogs Category dialog and message routines Delphi syntax: procedure ShowMessage(const Msg: string); procedure ShowMessage(const Msg: WideString); overload; procedure ShowMessage(const Msg: WideString; Params: array of const); overload; C syntax: extern PACKAGE void __fastcall ShowMessage(const AnsiString Msg); extern PACKAGE void __fastcall ShowMessage(const WideString Msg); extern PACKAGE void __fastcall ShowMessage(const WideString Msg, const System::TVarRec * Params, const int Params_Size); Description Call ShowMessage to display a simple message box with an OK button. The name of the application's executable file appears as the caption of the message box. Msg parameter is the message string that appears in the message box. Params lists the values to insert into Msg if the Msg string includes formatting specifiers. For more information about how messages are formatted, see Format Strings. Params_size is the index of the last value in Params (one less than the number of elements). Note: To display a message in a message box with other buttons, or with an icon, use the MessageDlg function. Note: If the user types Ctrl C in the message box, the text of the message is copied to the clipboard. } {***********************************************************} ********************* 如果您滿意答案,請結案 *********************
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
系統時間:2024-05-08 1:32:34
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!