Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2005

Tip: Looking for answers? Try searching our database.

XP Autoplay and IHWEventHandler implementation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RonNanko@gm-squared.de - 14 Sep 2005 12:03 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.