Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Creating a WIA Device Manager

The first step in using Windows Image Acquisition (WIA) services is to obtain an IWiaDevMgr interface pointer (if you are programming for Windows XP or earlier) or an IWiaDevMgr2 interface pointer (if you are programming for Windows Vista or later). To do this, call CoCreateInstance with the appropriate parameters. The sample application WiaSSamp creates a device manager within a global function implemented by the following code:

    HRESULT CreateWiaDeviceManager( IWiaDevMgr **ppWiaDevMgr ) //XP or earlier
    HRESULT CreateWiaDeviceManager( IWiaDevMgr2 **ppWiaDevMgr ) //Vista or later
        // Validate arguments
        if (NULL == ppWiaDevMgr)
            return E_INVALIDARG;

        // Initialize out variables
        *ppWiaDevMgr = NULL;

        // Create an instance of the device manager
        //XP or earlier:
        HRESULT hr = CoCreateInstance( CLSID_WiaDevMgr, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr, (void**)ppWiaDevMgr );

        //Vista or later:
        HRESULT hr = CoCreateInstance( CLSID_WiaDevMgr2, NULL, CLSCTX_LOCAL_SERVER, IID_IWiaDevMgr2, (void**)ppWiaDevMgr ); 

        // Return the result of creating the device manager
        return hr;

In this example, CLSID_WiaDevMgr and IID_IWiaDevMgr are WIA constants that represent the class ID and the interface ID of IWiaDevMgr, respectively. CLSID_WiaDevMgr2 and IID_IWiaDevMgr2 are WIA constants that represent the class ID and the interface ID of IWiaDevMgr2, respectively.

The value for the dwClsContext argument of the CoCreateInstance call must be CLSCTX_LOCAL_SERVER. No other server type is supported, and Component Object Model (COM) rejects any other value for this parameter.



Community Additions

© 2015 Microsoft