How the Shell Accesses Shell Extension Handlers

The shell uses two interfaces to initialize instances (objects created by IClassFactory::CreateInstance) of shell extensions: IShellExtInit and IPersistFile. The shell uses the IShellExtInit interface to initialize instances of context menu handlers, drag and drop handlers, and property sheet handlers. The shell uses IPersistFile to initialize instances of icon handlers, data handlers, and drop handlers. This interface is defined by OLE.

The IShellExtInit interface adds an additional member function, Initialize, to the standard IUnknown interface. A handler's Initialize function should keep a copy of the parameters that the shell passes to the function for later use. An example showing how to initialize instances follows.

STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
LPDATAOBJECT pDataObj, HKEY hRegKey)

{

// Initialize can be called more than once.

if (m_pDataObj)

m_pDataObj->Release();

// Save the object pointer.

if (pDataObj) {

m_pDataObj = pDataObj;

pDataObj->AddRef();

}

// Duplicate the registry handle.

if (hRegKey)

RegOpenKeyEx(hRegKey, NULL, 0L, MAXIMUM_ALLOWED,

&this->hRegKey);

return NOERROR;

}

A shell extension handler must implement three functions: an entrypoint function (often called DllMain or LibMain), DllCanUnloadNow, and DllGetClassObject.

DllCanUnloadNow and DllGetClassObject are essentially the same as they would be for any OLE in-process server DLL. The use of DllCanUnloadNow is shown in the following example.

STDAPI DllCanUnloadNow(void)

{

// g_cRefThisDll must be placed in the instance-specifc
// data section.

return ResultFromScode((g_cRefThisDll==0) ? S_OK : S_FALSE);

}

DllGetClassObject needs to expose the class factory for the object in the DLL. For more information about exposing the class factory, see the OLE documentation included in the Microsoft® Win32® Software Development Kit (SDK). The following example shows how to expose the class factory.

// DllGetClassObject - a DLL entrypoint function used by
// most in-process server DLLs.

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)

{

*ppvOut = NULL; // assume failure

if (IsEqualIID(rclsid, CLSID_ShellExtension)) {

return CShellExtSample_Create(riid, ppvOut);

} else {

return CLASS_E_CLASSNOTAVAILABLE;

}

}

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database