在WIA中,如何将我的程序添加到从数码相机获取图像的程序列表中?
当我将数码相机连接到计算机时,会出现一个对话框,其中包含所有已注册的程序,可用于从相机获取图像。 现在我想在列表中添加我自己的程序,这样当我单击我的程序的项目时,我可以使用我自己的程序从数码相机获取图像。
非常感谢。
When I connect my digital camera with my computer, a dialog box containing all the registered programs can be used to get images from the camera will appear. Now I want to add my own program in the list, so that when I click the item of my program, I can use my own program to get images from the digital camera.
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WIA 有一个设备管理器对象,它提供了一个允许程序注册事件通知的接口。
联系设备管理器
您可以使用
IWiaDevMgr
界面与设备管理器进行交互。 通过调用CoCreateInstance()
,您可以获得指向该接口的指针:为事件注册一个程序
然后,注册一个在事件触发时运行的程序就像这样简单:
命令行、名称、描述和图标都是
BSTR
,因为它们是通过COM 接口传递的。 您可以使用 SysAllocString() 及其朋友来创建它们,也可以使用 Visual C 扩展或 ATL 提供的类来创建和管理它们。释放设备管理器
如果您没有在接口中使用 COM 感知的智能指针,那么请不要忘记释放
CoCreateInstance()
所获取的引用:如果您不释放它, COM 系统会找到一种方法来惩罚您,但可能不会立即明显...
取消注册
休闲测试表明,当用于注册事件的所有四个参数都准确传递时,删除注册事件是有效的。 调用是:
这是一个潜在的烦恼,因为似乎没有记录的 API 来列出已注册的事件。 这意味着如果您的安装程序注册了一个程序,那么它还应该保留所使用的参数的记录,以便您的卸载程序可以取消注册该事件。
事件参数
命令行可以包含字符串
%1
和%2
,它们将分别替换为触发事件之前的端口名称和 GUID。命令行已解析。插入相机后,图标、名称和描述将显示在向用户呈现的列表中。名称应短于描述。
该图标是文件名和资源标识符的组合。 一个好的默认值是“sti.dll,0”,它将是相机和扫描仪的通用图像。 如果您提供自己的图标,则该字符串几乎肯定必须包含 DLL 的完全限定路径。 大胆地说,我想故意在路径中的任何位置包含一个逗号(而不是作为资源 id 之前的分隔符)会引起麻烦。
幕后
WIA/STI 存储事件列表的实际位置没有记录。 然而,通过在 regedit 中进行一些搜索,我在我的 XP SP3 系统上找到了事件目录。 人们可能会想象它会在其他系统中的类似位置找到...
注册表项 HKLM\SYSTEM\CurrrentControlSet\Control\StillImage\Events 包含系统已知的每个事件的子项。 每个键都有一个名为 GUID 的值,其中包含标识该事件的 GUID。
例如,Device Connected 事件处理程序列在
Connect
子项中。各个 WIA/STI 设备的密钥可以在
HKLM\SYSTEM\CurrentControlSet\Control\Class\{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}
密钥等位置找到。请记住,这些位置没有记录。 触摸它们需要您自担风险,您的里程会有所不同,...
WIA has a Device Manager object that provides an interface that allows for programs to register for event notifications.
Contacting the Device Manager
You use the
IWiaDevMgr
interface to interact with the device manager. You get a pointer to that interface with a call toCoCreateInstance()
:Registering a program for an event
Then, registering a program to be run when the event fires is as simple as:
The command line, name, description, and icon are all
BSTR
s because they are passing through a COM interface. You can either useSysAllocString()
and its friends to create them, or use the classes supplied by Visual C extensions or ATL to create and manage them.Releasing the Device Manager
If you aren't using a COM-aware smart pointer for the interface, then don't forget to release the reference taken by
CoCreateInstance()
:If you don't release it, the COM system will find a way to punish you, but it might not be immediately obvious...
Unregistration
Casual testing shows that deleting a registered event works when all four parameters used to register the event are passed exactly. The call is:
This is a potential annoyance because there seems to be no documented API to list the registered events. This implies that if your installer registers a program, then it should also keep a record of the arguments used so that your uninstaller can unregister the event.
The event parameters
The command line can contain the strings
%1
and%2
which will be replaced by the port name and the GUID of the event that fired, respectively, before the command line is parsed.The icon , name and description are displayed in the list presented to the user when the camera is plugged in. The name should be shorter than the description.
The icon is a combination of a file name and a resource identifier. A good default value is
"sti.dll,0"
which will be a generic image of a camera and scanner. If you supply your own icon, the string almost certainly must include a fully-qualified path to the DLL. Going out on a limb, I'd imagine that deliberately including a comma anywhere in the path other than as the separator before the resource id will cause trouble.Behind the scenes
The actual location where WIA/STI stores the list of events is not documented. However, with a little searching in regedit, I located the event catalog on my XP SP3 system. One might imagine that it would be found in a similar location in other systems...
The registry key
HKLM\SYSTEM\CurrrentControlSet\Control\StillImage\Events
contains a subkey for each event known to the system. Each key has a value named GUID containing the GUID that identifies that event.Device Connected event handlers are listed in the
Connect
subkey, for example.Keys for individual WIA/STI devices can be found in the
HKLM\SYSTEM\CurrentControlSet\Control\Class\{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}
key among other places.Remember that these locations are not documented. Touch them at your own risk, your mileage will vary, ...
您需要使用 WIA(Windows 图像采集)接口。 IWiaDevMgr 提供了三种方法来执行此操作:RegisterEventCallbackProgram、RegisterEventCallbackCLSID 和 RegisterEventCallbackInterface。 如果您希望 Windows 在用户在“自动播放”对话框中单击您时启动您的程序,您可以使用 RegisterEventCallbackProgram 或 RegisterEventCallbackCLSID。
You need to use the WIA (Windows Image Acquisition) interface. IWiaDevMgr provides three methods to do this: RegisterEventCallbackProgram, RegisterEventCallbackCLSID, and RegisterEventCallbackInterface. If you want Windows to start your program when the user clicks you in the Autoplay dialog, you can use either RegisterEventCallbackProgram or RegisterEventCallbackCLSID.