Auto detect device in window's service

  • Thread starter Thread starter Hank
  • Start date Start date
H

Hank

Hi,
I am writing a windows service application which manage image capturing
device in C#.NET.
When the service is running, how it automatically detect when there is a new
device plugged in (say through a USB port or Ethernet Adapter)?
Your help is highly appreciated!

Hank
 
Hi

We can use Windows Image Acquisition, but that is usually used in C++, it
is hard to use in VB6 or .NET, because it did not have typelib.

But it has Automation Layer for it.
Windows Image Acquisition Automation Layer
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wiaaut/wia/
wiax/overviews/startpagewiaaut.asp

So that we can use that layer in .NET.
We need to download the Windows® Image Acquisition Automation Library v2.0
Tool: Image acquisition and manipulation component for VB and scripting via
the link below.

http://www.microsoft.com/downloads/details.aspx?FamilyID=a332a77a-01b8-4de6-
91c2-b7ea32537e29&DisplayLang=en

Then we just need to add a reference to the wiaaut.dll in .NET for usage.

WIA.DeviceManager oDM = new WIA.DeviceManagerClass();
private void button1_Click(object sender, System.EventArgs e)
{
oDM.RegisterEvent(WIA.EventID.wiaEventDeviceConnected,"*");
oDM.OnEvent+=new
WIA._IDeviceManagerEvents_OnEventEventHandler(oDM_OnEvent);
}

private void oDM_OnEvent(string EventID, string DeviceID, string ItemID)
{
System.Diagnostics.Debug.Write(DateTime.Now.ToLongDateString());
System.Diagnostics.Debug.WriteLine("EventID: " + EventID);
System.Diagnostics.Debug.WriteLine("DeviceID: " + DeviceID);
System.Diagnostics.Debug.WriteLine("ItemID: " + ItemID);
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Peter:
Thanks for prompt response. I have following:
(1) I am using C#.NET in visual studio 2005 Beta
(2) I downloaded the WIAA Library wiaaut.dll, however when I tried to add
reference to my project, it says:
"A reference to C:\hang\.......\waiaut.dll could not be added. Please
make sure that the file is accessible, and that it is a valid assembly or
COM component."
(3)Do the library support C#?
(4)based on the description, this library only for XP, but my client use
both XP and windows 2000, 2003.
(5)I am little confused by the name "Windows Image Acquisition", some of my
devices use USB or Ethernet device to connect to destination image capturing
device, so my service need to detect USB or Ethnernet and etc. first.

Thanks!
Hang
 
Hi

(1)Since VS.NET 2005(Whidbey ASP 2.0) has not been released, it is still in
the beta
test period, so the behavior may be different from the final release.
So far Whidbey issue is not officially supported.
For Whidbey issue, you may try to post in vs2005 forum.
http://lab.msdn.microsoft.com/vs2005/community/

(2)Have you tried to following the steps in the readme of the download
package?
e.g. regsvr32 to register the dll

(3) Yes, as you see, my test code is based on C# VS.NET 2003

(4) Thanks for your response, the WIA needed windowxp at least, so in
windows 2000 we may need some more low level API, which usually written in
C++.
Since I am not very familar with multimedia development, so I would suggest
try to post in the newsgroup below which has more experts on media device
related development.
microsoft.public.win32.programmer.mmedia

(5) Based on my understanding, "Windows Image Acquisition" means the
approach to capture media including DC,DV .....
Also my test code in my last post, I test with a USB WebCam and it works.

If you still have any concern, please feel free to post here.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top