Problem using WIA

Discussion in 'Visual C# .Net' started by DN Admin, Sep 22, 2011.

  1. DN Admin

    Staff Member

    Aug 7, 2010
    Joliet, IL U.S.A.
    I'm developing an application using WIALib and WIAVIDEOLib to access a webcam. The application is intended for running on all versions of Windows from XP onward. It works just fine on my development system, which is on an XP machine. But when I
    run it under Vista I get an error. I "think" the error is happening when it's trying to

    <pre>wiaManager = new WiaClass();</pre>

    but I can't quite tell because I don't have Visual Studio installed on that Vista machine where I was testing it.<br/>
    The error message I get is:
    Program Error: <br/>
    FindDeviceById FAILED Retrieving the COM class Factory for component with CLSID {4EC4272E-2E6F-4EEB-91D0-EBC4D58E8DEE} Failed due to the following error: 80040154

    The "FindDeviceById" is the name of my function within which the error appears to occur.
    What do I have to do to correct this and have it run on ALL versions of Windows from XP onward? This is going to be a commercial product so it needs to install and run without the user having to do additional installations himself. It must be completely

    My entire FindDeviceById function is:
    <pre> private string getBracketedPartOfUSBId(string iD)
    int indexOfLeftCurlyBracket = iD.IndexOf('{');
    int indexOfRightCurlyBracket = iD.IndexOf('}');
    int lengthOfBracketedPart = indexOfRightCurlyBracket - indexOfLeftCurlyBracket + 1;
    string bracketedPart = iD.Substring(indexOfLeftCurlyBracket, lengthOfBracketedPart);

    return bracketedPart;

    private ItemClass FindDeviceById(string iDSeeking)
    // Returns the device or null if not found.
    CollectionClass wiaDevs = null;
    DeviceInfoClass devInfo = null;

    object foundID = null;
    ItemClass deviceFound = null;

    iDSeeking = getBracketedPartOfUSBId(iDSeeking);
    iDSeeking = iDSeeking.ToUpper();

    wiaManager = new WiaClass();

    // Get all devices.
    wiaDevs = wiaManager.Devices as CollectionClass;
    if (wiaDevs != null)
    foreach (object wiaObj in wiaDevs)
    devInfo = (DeviceInfoClass)Marshal.CreateWrapperOfType(wiaObj, typeof(DeviceInfoClass));

    string idFound = getBracketedPartOfUSBId(devInfo.Id);
    idFound = idFound.ToUpper();

    if (idFound == iDSeeking)
    foundID = devInfo.Id;
    deviceFound = (ItemClass)wiaManager.Create(ref foundID);
    devInfo = null;

    if (deviceFound != null)
    return deviceFound;
    return null;
    catch (Exception e)
    MessageBox.Show(this, "PROGRAM ERROR: FindDeviceById FAILED." + "n" + e.Message, "Movie Film Digitizer", MessageBoxButtons.OK, MessageBoxIcon.Stop);
    return null;
    if (devInfo != null)
    if (wiaDevs != null)
    if (wiaManager != null)
    Marshal.ReleaseComObject(wiaManager); wiaManager = null;

    View the full article

Share This Page