Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-12

Recognize a "disk"

10 messages · 7 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matt Shaffer
to Arí Ricardo Ody

I don't know that there's any direct way of finding out the last drive to be added, but if you monitor the drives every 5 seconds or so you can determine which is the newest one to be added (but that won't necessarily mean it's your windows mobile, so I hope you have a way of checking!)

2009/12/16 "Ar? Ricardo Ody"

Show quoted text 24 lines
Hi! Suppose you connect a Handheld running windows mobile via USB cable to a windows machine. Is there a way that I can recognize the new disk added to the system, e.g., determine what of the disks existing in the windows machine is the disk added when I connected the handheld? Greetings from Sao Paulo - Brazil Ricardo -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20091216/9cf4c4b7/attachment.html>

Reply by email

Felipe Monteiro de Carvalho
to Matt Shaffer

Hello,

Here you can find code to list all drives in Windows:

http://wiki.freepascal.org/Windows_Programming_Tips#Listing_all_available_drives

I don't know how to get warned when a drive is added, but as said you could periodically check the drives, and probably the drive type can help check if it is a pocketpc or not. I don?t know which type is for pocketpc but a simple test should show this.

bye,

Felipe Monteiro de Carvalho

Reply by email

Henry Vermaak
to Arí Ricardo Ody: -------------- next part -------------- An HTML attachment was scrubbed... URL:…

2009/12/16 "Ar? Ricardo Ody" :

Show quoted text 8 lines
Hi! Suppose you connect a Handheld running windows mobile via USB cable to a windows machine. Is there a way that I can recognize the new disk added to the system, e.g., determine what of the disks existing in the windows machine is the disk added when I connected the handheld?

Google around for examples using the wm_devicechange message. E.g. there is a discussion here:

http://www.codeproject.com/KB/dotnet/devicevolumemonitor.aspx

Henry

Reply by email

cobines
to Felipe Monteiro de Carvalho: Here you can find code to list all drives in Windows:…

2009/12/16 Felipe Monteiro de Carvalho :

I don't know how to get warned when a drive is added, but as said you could periodically check the drives, and probably the drive type can help check if it is a pocketpc or not. I don?t know which type is for pocketpc but a simple test should show this.

Capturing WM_DEVICECHANGE message with wParam=DBT_DEVICEARRIVAL might helpful.

cobines

Reply by email

cobines
to Arí Ricardo Ody

2009/12/16 "Ar? Ricardo Ody" :

I have no idea how I can capture the mentioned message. Could you send an example, please?

I have attached a few functions, but it's not complete example. I don't have access to windows right now.

Call SetMyWndProc() with a handle of your main form to hook into message queue and add code to handle WM_DEVICECHANGE in MyWndProc().

cobines -------------- next part -------------- var OldWProc: WNDPROC; function MyWndProc(hWnd: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin case uiMsg of WM_DEVICECHANGE: if (wParam = DBT_DEVICEARRIVAL) or (wParam = DBT_DEVICEREMOVECOMPLETE) then begin // Device added or removed detected. // Add handling code here. Exit(TRUE); end; end; Result := CallWindowProc(OldWProc, hWnd, uiMsg, wParam, lParam); end; procedure SetMyWndProc(Handle : THandle); begin OldWProc := WNDPROC(SetWindowLong(Handle, GWL_WNDPROC, LONG_PTR(@MyWndProc))); end; // Somewhere in OnCreate of your main form. procedure TMainForm.FormCreate(Sender: TObject); begin SetMyWndProc(Handle); end;

Reply by email

Sven Barth

Hello together!

2009/12/16 "Ar? Ricardo Ody"

Show quoted text 7 lines
Suppose you connect a Handheld running windows mobile via USB cable to a windows machine. Is there a way that I can recognize the new disk added to the system, e.g., determine what of the disks existing in the windows machine is the disk added when I connected the handheld?

As far as I know a Windows Mobile device is not recognized as a real volume or disk. That directory you see in Windows Explorer is a virtual directory which relies on the Remote API (RAPI) to communicate with the device and to display/modify its contents.

I also tested the WM_DEVICECHANGE approach: it is not working (as expected by me) - but it works well with an SD card...

There are two possibilities you can handle this:
* Try to connect with RAPI to your device. You can call the init function with an Event, that will be set once a device shows up (or an error happens). You need to use WaitForSingleObject for this.
* Add an entry to "HKLM\Software\Microsoft\Windows CE Services\AutoStartOnConnect" which contains an application (Name: Something, Value: your application path + parameters), that will be started once an ActiveSync connection is established. This application can for example notify your main application about this event. There is also an AutoStartOnDisconnect key containing applications that will be started once a device has been disconnected. (These keys also exist on Vista with Windows Mobile Device Center installed)

Note: for working with the file system of a Windows Mobile device you ALWAYS need to use RAPI (well... except you "export" the storage card of your device with WM5torage).

Regards,
Sven

Reply by email

bobby
to Sven Barth: Hello together! 2009/12/16 "Ar? Ricardo Ody" As far as I know a Windows Mobile device is…
Sven Barth wrote 46 lines
Hello together! 2009/12/16 "Ar? Ricardo Ody" > Suppose you connect a Handheld running windows mobile via USB cable to a > windows machine. > > > Is there a way that I can recognize the new disk added to the system, > e.g., > determine what of the disks existing in the windows machine is the disk > added when I connected the handheld? As far as I know a Windows Mobile device is not recognized as a real volume or disk. That directory you see in Windows Explorer is a virtual directory which relies on the Remote API (RAPI) to communicate with the device and to display/modify its contents. I also tested the WM_DEVICECHANGE approach: it is not working (as expected by me) - but it works well with an SD card... There are two possibilities you can handle this: * Try to connect with RAPI to your device. You can call the init function with an Event, that will be set once a device shows up (or an error happens). You need to use WaitForSingleObject for this. * Add an entry to "HKLM\Software\Microsoft\Windows CE Services\AutoStartOnConnect" which contains an application (Name: Something, Value: your application path + parameters), that will be started once an ActiveSync connection is established. This application can for example notify your main application about this event. There is also an AutoStartOnDisconnect key containing applications that will be started once a device has been disconnected. (These keys also exist on Vista with Windows Mobile Device Center installed) Note: for working with the file system of a Windows Mobile device you ALWAYS need to use RAPI (well... except you "export" the storage card of your device with WM5torage). Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Hi,

It depends how your device connects to the PC.
I'm developing some little apps for PNA (personal navigation) lately. Some of them will add new drive to the system (most of them will add two new drives, internal flash and external SD card), but some uses ActiveSync to communicate with PC.
I didn't work a lot with the latter one, and for these which are adding new drives to Explorer - there WM_DEVICECHANGE works just fine.

regards
bobby

Reply by email