I've been trying to get a delphi Application to receive this message whenever the user wants to eject a pen in order for it to stop anything it might be doing with the pen (close file handles and so on) and let the user remove the pen without having windows say it's being used. Problem is, I can only receive DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE.
It seems that in order to receive the rest, you've got to use DEV_BROADCAST_HANDLE with dbch_handle := a handle to the pen you want to monitor. I've currently got some code I got from all over the web but it gives a Windows Error 1066 when run (even tough it's running as a normal user application):
[code]Function TForm2.MessageRegisterFile: Boolean;
result := False;
Size := SizeOf(DEV_BROADCAST_HANDLE);
dbi.dbch_size := Size;
dbi.dbch_devicetype := DBT_DEVTYP_HANDLE;
dbi.dbch_reserved := 0;
hdir:=CreateFile ('\.H:',GENERIC_READ,FILE_SHARE_READ or FILE_SHARE_WRITE
r := RegisterDeviceNotification(Form2.Handle, @dbi
if Assigned(r) then result := True;
It always returns false, and Showmessages "1066".
CreateFile doesn't return any error (I tested).
I've been at this for hours and would appreciate it if anybody could help, since I'm not familiar enough with the Windows API to fix this.
Or if anyone knows a VCL Component that does what I want without me having to mess with this part of the Windows API, I'd appreciate it.