Detect Pendrives connected

HMG Samples and Enhancements

Moderator: Rathinagiri

RPC
Posts: 285
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: Detect Pendrives connected

Post by RPC »

mustafa wrote: Thu Mar 05, 2020 6:40 pm Hello here I put the summary code
only detect if this USB flash drive
and cancel
This last option in Win-10 disconnects
but the unit stays on
Mustafa
Hi Mustafa
You are right, this works on pen drive.
It does not work on external HDD

Decrypt_tools doesn't work wit bat file also. No executable file is produced.
User avatar
mustafa
Posts: 1160
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Detect Pendrives connected

Post by mustafa »

Hola amigo RPC
Te mando un pequeño esquema como yo he compilado la aplicación
No he probado la de 32 bits ya que yo estoy trabajando con 64 bits
Build.3.4.4_64.Bat si tienes instalado HMG en otra dirección
tienes que modificar el Fichero Bat

Dentro de Decrypt_Help tienes una pequeña Demo --> Decrypt_Tools.gif
que nada mas de des 2 cliks con el mouse se empezara a ver.

PD. hoy he probado una tarjeta de Memoria SD y el sample asumido
como PendDrive en mi ordenador -> F: y he podido hacer Back_up

Regards/Saludos
Mustafa
*-------------------------------------- Google ---------------------------------*
Hello Friend RPC
I send you a small scheme as I have compiled the application
I have not tried the 32-bit since I am working with 64 bits
Build.3.4.4_64.Bat if you have HMG installed in another address
you have to modify the Bat File

Within Decrypt_Help you have a small Demo -> Decrypt_Tools.gif
that nothing more than des 2 clicks with the mouse will begin to see.

P.S. Today I tried an SD Memory Card and the assumed sample
as PendDrive in my computer --> F: and I have been able to do Back_up

Regards / Saludos
Mustafa
Attachments
Imagen2.jpg
Imagen2.jpg (105.8 KiB) Viewed 2229 times
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Detect Pendrives connected

Post by AUGE_OHR »

mustafa wrote: Fri Mar 06, 2020 10:28 am I don't know how to interpret your writing code
I could put a small complete sample just
concerning the detection of USB PenDrive drives

With this code it only detects if this PenDrive
Inside USB Drive

Code: Select all

 For i := 1 To 32
   If IsBit ( nBitMask , i )                 // <------ função IsBit da biblioteca LIBCT.LIB
   MsgInfo(   Aadd( aDrives, Chr(64+i)+":\" ) )
   EndIf
 Next i
here is a Function that did same

Code: Select all

FUNCTION GetDrive( nMask )
Local cBin := NToC ( nMask, 2 )
Local nBit:= Len ( cBin ) - hb_At( '1', cBin )
RETURN Chr( nBit + 65 ) + ":"
but i call this Function when get WM_DEVICECHANGE Event

Code: Select all

FUNCTION USB_Detect()
LOCAL nHWnd    := EventHWND()
LOCAL nMsg     := EventMSG()
LOCAL nWParam  := EventWPARAM()
LOCAL nLParam  := EventLPARAM()
LOCAL nMask, cDevice := ""
Local xRet
Local lThreatRet := hb_mutexSubscribe( s_mtxReturn, 0.00000001, @xRet ) 

DO CASE

   CASE lThreatRet .AND. hb_isArray ( xRet )
   	 //return message from Wait4Action thread
   	 Msginfo( xRet[1], STR( xRet[2] ) )

   CASE nMsg == WM_DEVICECHANGE
      DO CASE
         CASE nWParam == DBT_DEVICEARRIVAL
            nMask    := DeviceChangeInfo( nWParam, nLParam )
            if !Empty( nMask ) .and. nMask > 0
               cDevice := GetDrive( nMask )
            endif
            //send job
            hb_mutexNotify( s_mtxUSB, { "INSERT", cDevice, nMask, nHWnd } )

         CASE nWParam == DBT_DEVICEREMOVECOMPLETE
            nMask    := DeviceChangeInfo( nWParam, nLParam )
            if !Empty( nMask ) .and. nMask > 0
               cDevice := GetDrive( nMask )
            endif
            //send job
            hb_mutexNotify( s_mtxUSB, { "REMOVE", cDevice, nMask, nHWnd } )
      End CASE
End Case
RETURN cDevice
so try modify Sample from edk who have told me to use MUTEX
have fun
Jimmy
User avatar
mustafa
Posts: 1160
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Detect Pendrives connected

Post by mustafa »

Hi jimmy
Thanks for your interest

Regards/Saludos
Mustafa
RPC
Posts: 285
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: Detect Pendrives connected

Post by RPC »

Hi Mustafa
Your program uses "hmg_GFilatov.ch" I don't seem to have this header file in my C:\hmg.3.4.4\INCLUDE folder.
Could that be the reason for not compiling/linking ?
Thanks
User avatar
mustafa
Posts: 1160
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Detect Pendrives connected

Post by mustafa »

Hi RPC
the file "hmg_GFilatov.ch" is included
in my Sample zip package, if you look
in the screenshot that I sent you in the previous Post
"hmg_GFilatov.ch" is the third after the 2 files
build.3.4.4. bat, if you look at the screenshot you only have
what to use to compile if you have HMG installed as
I have it ? or you have to modify the bat file, look
that you have to compile as represented in the screenshot
the file ---> Decrypt_Tools.hbp, see if your HMG is installed
as the Bat is say C: \ hmg.3.4.4 \ build.bat

PD: The Library of GFilatov ---> "hmg_GFilatov.ch" makes the ornament
from the box that you have to the right of the screenshot, can it be deleted?

Code: Select all


 DEFINE WINDOW Form_003                      ;
        At 0,0 Width 650 Height 592          ; 
        Title 'Decrypt_Tools Files Zip 2020' ;
        ICON "Logo"                          ;
        MAIN NOSIZE NOMAXIMIZE 
  
        ON KEY ESCAPE ACTION Form_003.Release  
      
        DrawWindowBoxRaised( "Form_003" , 10, 10, 500, 633 )      //<------------------ Lib "hmg_GFilatov.ch"

View Demo ---> viewtopic.php?f=8&t=5864&p=57940&hilit= ... ile#p57940
HB_ZIP_Demo_v01_New.zip

There is luck.
Regards
Mustafa
User avatar
mustafa
Posts: 1160
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Detect Pendrives connected

Post by mustafa »

Hola amigos
Aqui teneis una nueva muestra de detección
USB-Pendrive , en mi Ordenador me están saliendo
las unidades que en esta muestra os presento

Me esta detectando la Tarjeta de Memoria como Letra F:
igual que la Unidad Usb y puedo mandar ficheros Zip Back-up
A través de mi sample "USB-PenDrive.exe" sin ningún
problema.
Saludos
Mustafa
*---------------------------- Google ---------------------------*

Hello friends
Here you have a new detection sample
USB-Pendrive, on my Computer they are coming out
the units that in this sample I present to you

The Memory Card is being detected as Letter F:
same as Usb PenDrive and I can send Zip Back-up files
Through my sample "USB-PenDrive.exe" without any
problem.
Regards
Mustafa
Attachments
USB-Detect2.zip
(131.51 KiB) Downloaded 148 times
Pantallazo.jpg
Pantallazo.jpg (74.76 KiB) Viewed 2133 times
RPC
Posts: 285
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: Detect Pendrives connected

Post by RPC »

Hi Mustafa
USB_Detect2 works.
It shows both the pen drive and also external HDD when connected.
Many thanks
User avatar
mustafa
Posts: 1160
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Detect Pendrives connected

Post by mustafa »

Hello friend RPC
In my sample how it is marking the attached screenshot
I am marking the Hard Disk C: and D: DVD E: and the
USB-Pendrive as F: and Memory Card also as
letter F:

In your case, which Unit letters do you get? the
External Hard Drive also as letter F:?

Greetings
Mustafa
RPC
Posts: 285
Joined: Fri Feb 10, 2017 4:12 am
DBs Used: DBF

Re: Detect Pendrives connected

Post by RPC »

Hi Mustafa
I have partitioned my HDD as C:,D: and E: so I get follo SS when I attach external HDD or pendrive
Attachments
USB-Detect.png
USB-Detect.png (1.26 MiB) Viewed 2069 times
Post Reply