STDMETHODIMP ShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter,
                                                   REFIID riid,
                                                   LPVOID *ppvObj)
{
    if(ppvObj == 0)
        return E_POINTER;

    *ppvObj = NULL;

    // Shell extensions typically don't support aggregation (inheritance)

    if (pUnkOuter)
        return CLASS_E_NOAGGREGATION;

    // Create the main shell extension object.  The shell will then call
    // QueryInterface with IID_IShellExtInit--this is how shell extensions are
    // initialized.

    ShellExt* pShellExt = new ShellExt(status_); // Create the ShellExt object

    const HRESULT hr = pShellExt->QueryInterface(riid, ppvObj);
    if(FAILED(hr))
        delete pShellExt;
    return hr;
}
Exemple #2
0
IFACEMETHODIMP Factory::CreateInstance(IUnknown* pUnkOuter, REFIID iid, void** ppv)
{
  dump(L"CreateInstance");

  if (pUnkOuter) {
    dump(L"CreateInstance - NoAggr");
    return CLASS_E_NOAGGREGATION;
  }
  ShellExt* inst = new(std::nothrow) ShellExt();

  if (!inst) {
    dump(L"CreateInstance - OOM");
    return E_OUTOFMEMORY;
  }

  // Get the requested interface.
  HRESULT hr = inst->QueryInterface(iid, ppv);

  if (FAILED(hr)) {
    dump(L"CreateInstance - Failed");
    delete inst;
  }
  else {
    dump(L"CreateInstance - OK");
  }
  return hr;
}