使用 OleCreatePropertyFrame 后 COINIT_MULTITHREADED 和神秘崩溃
在 DirectShow 应用程序中使用 COINIT_MULTITHREADED 有什么好处吗?目前它给我带来了一些麻烦,但我不确定使用 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) 是否是解决问题的正确方法。
完整的故事: 我有一个非常简单的网络摄像头捕获应用程序,能够选择捕获源并通过 OleCreatePropertyFrame 调用设备制造商设置。
我的应用程序运行相当稳定,没有内存泄漏,我可以毫无问题地在设备之间切换(每次用户选择设备时我都会完全重建 DirectShow 图形)。
但是显示捕获过滤器的属性页后只有一个问题。如果我只是显示它并关闭而不更改任何内容,一切都会正常进行。如果我更改属性页中的任何设置,然后关闭属性框架,一切都会看起来正常......直到下次我更改设备并重建图形。上一个图被正常销毁,没有错误,过滤器被正确删除和释放。当我创建一个新图表并调用 graphBuilder->SetFiltergraph( pfg ) 时,我的应用程序因 Kernel32 中的一些奇怪的访问冲突错误而崩溃。但如果我将 COINIT_MULTITHREADED 更改为 COINIT_APARTMENTTHREADED,此错误就会消失。
那么 COINIT_MULTITHREADED 是我的应用程序的真正问题吗?或者可能还有其他怪物隐藏在某处?有人有这方面的经验吗?
Is there any benefit of using COINIT_MULTITHREADED in a DirectShow application? For now it has given me some troubles, but I am not sure if using CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) is the right fix for the problems.
The full story:
I have a pretty straightforward web camera capture application with ability to choose the capture source and call the device manufacturer settings through OleCreatePropertyFrame.
My app runs pretty stable, no memory leaks, I can switch between devices without any problems (I completely rebuild DirectShow graph each time when user chooses device).
But there is only one problem after showing the property page of the capture filter. If I just show it and close without changing anything, all continues normally. If I change any setting in the property pages and then close the property frame, also everything continues seemingly normal .. until the next time I change the device and rebuild the graph. The previous graph gets destroyed normally, no errors, filters are being removed and released correctly. And right when I create a new graph and call graphBuilder->SetFiltergraph( pfg ), my app crashes with some weird access violation errors insde of Kernel32. But if I change COINIT_MULTITHREADED to COINIT_APARTMENTTHREADED, this error disappears.
So is that COINIT_MULTITHREADED a real problem of my application or maybe there is some other monster hiding somwhere? Has someone experince with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何创建窗口的线程都必须是 STA。 user32 和 gdi 本质上都是线程不安全的。
Any thread that creates a window must be STA. Both user32 and gdi are fundamentally thread-unsafe.