| Код | library testdll;
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }
uses SysUtils, Classes, ShareMem, ufTSWindow in 'ufTSWindow.pas' {Form4};
{$R *.res}
var HookDCWindow: TForm4;
procedure HookWMDeviceChange; begin if not Assigned(HookDCWindow) then begin HookDCWindow := TForm4.Create(nil); HookDCWindow.Show; // end; end;
procedure UnHookWMDeviceChange; begin if Assigned(HookDCWindow) then begin FreeAndNil(HookDCWindow); // end; end;
exports HookWMDeviceChange, UnHookWMDeviceChange;
begin end.
|
| Код | unit ufTSWindow;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type TForm4 = class(TForm) private procedure WMDeviceChange(var Message: TMessage); message WM_DEVICECHANGE; end;
var Form4: TForm4;
unique_number_in: boolean=false; unique_number_out: boolean=false; count_of_7_message: byte=0;
implementation
{$R *.dfm}
{ TForm4 }
procedure TForm4.WMDeviceChange(var Message: TMessage); begin if (Message.wParam=7) then inc(count_of_7_message); if (Message.wParam=32772) then unique_number_out:=true; if (Message.wParam=32768) then unique_number_in:=true; if (unique_number_out) and (count_of_7_message=3) then begin unique_number_out:=false; count_of_7_message:=0; ShowMessage('Флешка была отключена'); end;
if (unique_number_in) and (count_of_7_message=6) then begin unique_number_in:=false; count_of_7_message:=0; ShowMessage('Флешка была включена'); end;
// Memo1.Lines.Add('Пришло сообщение с кодом '+IntToStr(Message.wParam)); Inherited; end;
|
Что-то вроде, не проверял т.к. ничего флешового нету под рукой.
|