I am currently working on a new feature for my application (related to
audio cd and mp3 management) which contains a cd ripping feature.
What I would like to do is to present the application in the XP
Autostart feature as soon as an Audio CD is inserted into a cd drive.
So far I managed to get this entry into the list by setting the
appropriate registry settings and by clicking it, the related .exe is
called - so far so good.
However, how do I now go about determining for which drive the
executable was called? For instance, if there are two cd/dvd drives in
the system, I would like to start the ripping process for exactly the
drive, for which the autoplay-dialog was shown in the first place.
I think I need to implement the IHWEventHandler interface. How would I
go about doing this in my application? Can I simply add an interface
definition for my main windows form like this:
public class Form1 : System.Windows.Forms.Form, IHWEventHandler
with IHWEventHandler defined like this:
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
GuidAttribute("C1FB73D0-EC3A-4ba2-B512-8CDB9187B6D1")]
public interface IHWEventHandler
{
[PreserveSig()]
int HandleEvent(IntPtr in_sDeviceID, IntPtr in_sAltDeviceID, IntPtr
in_sEventType);
[PreserveSig()]
int Initialize(IntPtr in_sParams);
}
Apparently this is what I did, but neither the Initialize nor the
HandleEvent methods are called, instead the application starts normally
by showing it's winform.
What might the problem be here? Or is there another way to find out,
for which drive the autoplay feature was started? This would be
sufficient for my cause.
Thanks in advance,
Ron Nanko
Mattias Sjögren - 14 Sep 2005 17:22 GMT
>I think I need to implement the IHWEventHandler interface. How would I
>go about doing this in my application? Can I simply add an interface
>definition for my main windows form like this:
You can, but it would probably be better to implemente it in a
separate class.
>[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
>GuidAttribute("C1FB73D0-EC3A-4ba2-B512-8CDB9187B6D1")]
[quoted text clipped - 7 lines]
> int Initialize(IntPtr in_sParams);
>}
The methods are in the wrong order (Initialize should come before
HandleEvent) and the HandleEventWithContent method is missing.
>What might the problem be here?
Just implementing the interface will not suffice, you also have to
tell the shell about your implementation. This is described in the
sections "Registering a Handler for a Device Event" and "Using
AutoPlay Events in Running Applications" in this article
http://msdn.microsoft.com/library/en-us/shellcc/platform/Shell/programmersguide/
shell_basics/shell_basics_extending/autoplay/autoplay2k_cookbook.asp
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.