0

我有一个来自Codeplex的 WPF 网络摄像头组件的源代码,我正在尝试将其从 .NET 3.5 移植到 .NET 4.0。

在两个目标下都可以正常编译,但在 .NET 4.0 版本中,在此方法System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception的行中运行带有 a 的应用程序时会崩溃:moniker.BindToObject(bindCtx, null, ref filterId, out filterObject);

internal static IBaseFilter CreateFilter(string filterMoniker)
        {
            object filterObject = null;
            IBindCtx bindCtx = null;
            IMoniker moniker = null;

            int n = 0;

            if (CreateBindCtx(0, out bindCtx) == 0)
            {
                if (MkParseDisplayName(bindCtx, filterMoniker, ref n, out moniker) == 0)
                {
                    Guid filterId = typeof(IBaseFilter).GUID;
                    try
                    {
                        moniker.BindToObject(bindCtx, null, ref filterId, out filterObject);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex+"");
                    }

                    Marshal.ReleaseComObject(moniker);
                }
                Marshal.ReleaseComObject(bindCtx);
            }
            return filterObject as IBaseFilter;
        }

知道为什么以及如何解决它吗?

相机是Genius Eye 110,我在 Windows XP SP2 下工作。

4

1 回答 1

0

我下载了代码,用 4.0 编译它,它对我有用。你确定你有一个你的系统知道的网络摄像头吗?也许您可以检查设备管理器进行验证。

如果我的相机没有插上电源,程序会抛出类似于你的异常。

-马特

于 2010-07-20T12:31:53.040 回答