WPF Webcam component crashes under .NET 4.0
I've got a WPF webcam component's source-code from Codeplex that I'm trying to port from .NET 3.5 to .NET 4.0.
Compiles just fine under both targets, but in the .NET 4.0 version, it crashes when running the app with a System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception
at the line moniker.BindToObject(bindCtx, null, ref filterId, out filterObject);
in this method:
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开发者_StackOverflow中文版 IBaseFilter;
}
Any idea why and how to fix it?
The camera is a Genius Eye 110, and I'm working under Windows XP SP2.
I downloaded the code, compiled it with 4.0 and it worked for me. Are you sure that you have a webcam that your system knows about? Perhaps you can check the device manager to verify.
If my camera is not plugged it, the program throws an exception similar to yours.
-Matt
精彩评论