Prev: C#, COM problem
Next: How to copy icons used by VS?
From: kilic on 21 Oct 2009 14:59 How can I detect when a PnP is inserted and removed. Is there a way to catch this events in C#. I would appreciate if you could provide a code snippet. thx
From: Ben Voigt [C++ MVP] on 23 Oct 2009 15:06 "kilic" <u55638(a)uwe> wrote in message news:9defaca64e4e9(a)uwe... > How can I detect when a PnP is inserted and removed. Is there a way to > catch > this events in C#. > I would appreciate if you could provide a code snippet. > thx > RegisterDeviceNotification and SetupDi* They involve some messy Win32 API structures, so I'd strongly recommend using C++/CLI to build a .NET component which calls the Win32 APIs, then your C# code can consume the C++/CLI component.
From: kilic via DotNetMonster.com on 23 Oct 2009 16:20 Thanks Ben, I found an example using protected override void WndProc(ref Message m) { if (m.Msg == WM_DEVICECHANGE) .... the only issue I have now is that I don't get dbch_devicetype==DBT_DEVTYP_DEVICEINTERFACE, when I receive the WM_DEVICECHANGE message. I only get the dbch_devicetype == DBT_DEVTYP_PORT and DBT_DEVTYP_VOLUME.. I think I need to do use the RegisterDeviceNotification to get the DBT_DEVTYP_DEVICEINTERFACE, type. Do you have a simple code snippet example with RegisterDeviceNotification in C#, which you can post? Thanks, Ben Voigt [C++ MVP] wrote: >> How can I detect when a PnP is inserted and removed. Is there a way to >> catch >> this events in C#. >> I would appreciate if you could provide a code snippet. >> thx > >RegisterDeviceNotification and SetupDi* > >They involve some messy Win32 API structures, so I'd strongly recommend >using C++/CLI to build a .NET component which calls the Win32 APIs, then >your C# code can consume the C++/CLI component. -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-csharp/200910/1
From: Ben Voigt [C++ MVP] on 26 Oct 2009 18:29 "kilic via DotNetMonster.com" <u55638(a)uwe> wrote in message news:9e09871826252(a)uwe... > Thanks Ben, > > I found an example using > protected override void WndProc(ref Message m) > { > if (m.Msg == WM_DEVICECHANGE) > ... > the only issue I have now is that I don't get > dbch_devicetype==DBT_DEVTYP_DEVICEINTERFACE, when I receive the > WM_DEVICECHANGE message. > > I only get the dbch_devicetype == DBT_DEVTYP_PORT and DBT_DEVTYP_VOLUME.. Right. Windows doesn't send DBT_DEVTYP_DEVICEINTERFACE notifications unless you request them, because there are so many and most programs wouldn't have any use for them. > > I think I need to do use the RegisterDeviceNotification to get the > DBT_DEVTYP_DEVICEINTERFACE, type. Also right. > > Do you have a simple code snippet example with RegisterDeviceNotification > in > C#, which you can post? I don't. I follow my own advice and use C++/CLI for calling Windows API functions from .NET > > Thanks, > > > Ben Voigt [C++ MVP] wrote: >>> How can I detect when a PnP is inserted and removed. Is there a way to >>> catch >>> this events in C#. >>> I would appreciate if you could provide a code snippet. >>> thx >> >>RegisterDeviceNotification and SetupDi* >> >>They involve some messy Win32 API structures, so I'd strongly recommend >>using C++/CLI to build a .NET component which calls the Win32 APIs, then >>your C# code can consume the C++/CLI component. > > -- > Message posted via DotNetMonster.com > http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-csharp/200910/1 >
|
Pages: 1 Prev: C#, COM problem Next: How to copy icons used by VS? |