WIA.DeviceManager.DeviceInfos.Count = 0。为什么?
我正在尝试识别连接到计算机的扫描仪。 可能的解决方案之一是使用 WIA(Windows 图像采集自动化库)。
到目前为止,我的操作如下:
- 下载 wiaut.dll
- 将其复制到 system32
- 使用“regsvr32 wiaut.dll”注册它(成功)
- 在 Visual Studio.NET 中添加对我的项目的引用
- 检查 Windows 图像采集 (WIA) 服务是否正在运行
下一步,我添加并调试以下代码:
WIA.DeviceManager manager = new WIA.DeviceManagerClass();
string deviceName = "";
foreach (WIA.DeviceInfo info in manager.DeviceInfos)
{
if (info.Type == WIA.WiaDeviceType.ScannerDeviceType)
{
foreach (WIA.Property p in info.Properties)
{
if (p.Name == "Name")
{
deviceName = ((WIA.IProperty)p).get_Value().ToString();
Console.WriteLine(deviceName);
}
}
}
}
但是,manager.DeviceInfos 始终为空。 我连接了两台扫描仪,其中一台显示在“控制面板”->“扫描仪和相机”中,一台没有,并且两台扫描仪都显示在设备管理器的“成像设备”下。
关于为什么 WIA.DeviceManager.DeviceInfos 中没有出现任何建议?
在 Windows XP Service Pack 2 上运行
I'm trying to identify the scanners attached to the computer. One of the possible solutions is to use WIA (Windows Image Acquisition Automation Library).
These were my actions so far:
- Download wiaaut.dll
- Copy it to system32
- Register it with "regsvr32 wiaaut.dll" (successfully)
- Add reference to my project in Visual Studio.NET
- Check that the Windows Image Acquisition (WIA) service is running
Next, I add and debug the following code:
WIA.DeviceManager manager = new WIA.DeviceManagerClass();
string deviceName = "";
foreach (WIA.DeviceInfo info in manager.DeviceInfos)
{
if (info.Type == WIA.WiaDeviceType.ScannerDeviceType)
{
foreach (WIA.Property p in info.Properties)
{
if (p.Name == "Name")
{
deviceName = ((WIA.IProperty)p).get_Value().ToString();
Console.WriteLine(deviceName);
}
}
}
}
However, the manager.DeviceInfos is always empty. I have 2 scanners attached, one of them shows in Control Panel->Scanners and Cameras, one doesn't, and both show under "Imaging Devices" in Device manager.
Any suggestion on why none are appearing in WIA.DeviceManager.DeviceInfos?
Running on Windows XP Service Pack 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
这将在 Visual Studio 上显示为错误,但当您按 F5 时将进行编译。
并且会跑..
try this:
this will show like a error on visual studio but when you press f5 will compile.
and will run..
尝试一下这个类:
}
try it with this class:
}
我在java中使用这个,所以也许我的提示不正确,但我只在Windows Vista及更高版本中使用你提到的方法......
所以看起来您正在使用 wia 2.0,但对于 Windows ME 和 XP,您应该使用 wia 1.0,网址
为 MSDN 描述了..
也许会有帮助
I work with this in java so maybe my hint isnt correct, but i use your mentioned way only for windows vista and later...
so it looks like you are using wia 2.0 but for windows ME and XP you should use wia 1.0
At MSDN it is described..
maybe it will help
尝试更改行 :
并替换为:
我希望对您有所帮助。
Try change the line :
and replace with:
I hope i helped you.