Platform SDK: Active Directory, ADSI, and Directory Services

ICommonQuery::OpenQueryWindow

The ICommonQuery::OpenQueryWindow method opens the query dialog.

HRESULT OpenQueryWindow(
  HWND hwdnParent,
  LPOPENQUERYWINDOW *pQueryWnd,
  IDataObject **ppDataObj
);

Parameters

hwdnParent
[in] window to treat as the parent to the dialog displayed when this method is called.
*pQueryWnd
[in] a pointer to an OPENQUERYWINDOW structure describing the query to be performed and the characteristics of the window to be displayed.
ppDataObj
[out] Data object that can be used to read information about the query.

Return Values

This method returns an HRESULT value.

Remarks

The following is a C/C++ code snippet illustrating how to invoke the Directory Service Query to search for printers in Active Directory™. The ICommonQuery interface is called to specify a directory service query. The default form is set to Find Printers. The search begins after the dialog is initialized and the scopes collected. If the user selects a printer or more, the selection is returned via IDataObject.

#include "cmnquery.h"
#include "dsclient.h"
#include "dsquery.h"
 
...
 
HRESULT FindSomePrinters(void)
{
    HRESULT hres;
    ICommonQuery* pcq;
 
    hres = CoCreateInstance(CLSID_CommonQuery, NULL, CLSCTX_INPROC_SERVER, IID_ICommonQuery, (void**)&pcq);
    if ( SUCCEEDED(hres) )
    {
        OPENQUERYWINDOW oqw = { 0 };
        DSQUERYINITPARAMS dqip = { 0 };
        IDataObject *pdo;
 
        //
        // Initialize the OPENQUERYWINDOW structure to indicate 
        // we want to do a Directory Service
        // Query, the default form is printers and the search 
        // should start once the window is initialized.
        //
 
        oqw.cbStruct = SIZEOF(oqw);
        oqw.dwFlags = OQWF_OKCANCEL|OQWF_DEFAULTFORM|OQWF_ISSUEONOPEN;
        oqw.clsidHandler = CLSID_DsQuery;
        oqw.pHandlerParameters = &dqip;
        oqw.clsidDefaultForm = CLSID_DsFindPrinter;
 
        // 
        // Now initialize the handler specific parameters, 
        // in this case, the File/Save menu item is removed
        //
 
        dqip.cbStruct = SIZEOF(dqip);
        dqip.dwFlags = DSQPF_NOSAVE;
 
        //
        // Call OpenQueryWindow, it will block until 
        // the Query Window is dismissed, so it is advised that 
        // you run this code on a separate thread. 
        //
 
        hres = pcq->OpenQueryWindow(NULL /* no parent */, &oqw, &pdo);
        if ( SUCCEEDED(hres) && pdo )
        {
            FORMATETC fmte = {CF_HDROP, 
                      RegisterClipboardFormat(CFSTR_DSOBJECTNAMES), 
                      DVASPECT_CONTENT, 
                      -1, 
                      TYMED_HGLOBAL};
            STGMEDIUM medium = { TYMED_NULL, NULL, NULL };
 
            //
            // Retrieve the result from the IDataObject, 
            // in this case CF_DSOBJECTNAMES (dsclient.h) 
            // is needed because it describes 
            // the objects which were selected by the user.
            //
            // Also supported is CF_DSQUERYPARAMS which contains 
            // the LDAP filter and other information 
            //  on the query issued.
            //
 
            hres = pdo->GetData(&fmte, &medium);
            if ( SUCCEEDED(hres) )
            {
                DSOBJECTNAMES *pdon = (DSOBJECTNAMES*)GlobalLock(medium.hGlobal);
                if ( pdon )
                {
                    // pdon => DSOBJECTNAMES structure, 
                    // See dsclient.h for more information
 
                    GlobalUnlock(medium.hGlobal);
                }
            }
 
            ReleaseStgMedium(&medium);
            pdo->Release();
        }    
    }
 
    return hres;
}

Requirements

  Windows NT/2000: Requires Windows 2000.
  Header: Declared in Cmnquery.h.
  Library: Included as a resource in Cmnquery.dll.

See Also

Active Directory Display Interfaces, DSQUERYINITPARAMS, ICommonQuery, IDataObject, OPENQUERYWINDOW