HRESULT
STDMETHODCALLTYPE
CClassFactory::CreateInstance (
                               __in_opt IUnknown * /* OuterObject */,
                               __in REFIID InterfaceId,
                               __out PVOID *Object)
/*++
 
  Routine Description:

    This COM method is the factory routine - it creates instances of the driver
    callback class and returns the specified interface on them.

  Arguments:

    OuterObject - only used for aggregation, which our driver callback class
                  does not support.

    InterfaceId - the interface ID the caller would like to get from our 
                  new object.

    Object - a location to store the referenced interface pointer to the new
             object.

  Return Value:

    Status.

--*/
{
    HRESULT hr;

    PCUmdfVDev driver;

    *Object = NULL;

    hr = CUmdfVDev::CreateInstance (&driver);

    if (SUCCEEDED(hr)) 
    {
        hr = driver->QueryInterface (InterfaceId, Object);
        driver->Release ();
    }

    return hr;
}
Exemple #2
0
HRESULT
CUmdfVDev::CreateInstance ( 
                         _Out_ PCUmdfVDev *Driver)
/*++
 
  Routine Description:

    This static method is invoked in order to create and initialize a new 
    instance of the driver class.  The caller should arrange for the object
    to be released when it is no longer in use.

  Arguments:

    Driver - a location to store a referenced pointer to the new instance

  Return Value:

    S_OK if successful, or error otherwise.

--*/
{
    PCUmdfVDev driver;
    HRESULT hr;

    Enter();

    //
    // Allocate the callback object.
    //

    driver = new CUmdfVDev();

    if (NULL == driver)
    {
        return E_OUTOFMEMORY;
    }
        
    //
    // Initialize the callback object.
    //

    hr = driver->Initialize ();

    if (SUCCEEDED (hr)) 
    {
        //
        // Store a pointer to the new, initialized object in the output 
        // parameter.
        //
        *Driver = driver;
    }
    else 
    {

        //
        // Release the reference on the driver object to get it to delete 
        // itself.
        //

        driver->Release ();
    }

    ExitHR(hr);
    return hr;
}