Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Data Transfer, COM Enums, and Windows Controls


Data Transfer, COM Enums, and Windows Controls

Listing 3 Implemenation of ListExchange_PutItems_Base()


/* /////////////////////////////////////////////////////////////
 * ...
 *
 * Extract from MOCtlFns.c
 *
 * Copyright (C) 1998-2003, Synesis Software Pty Ltd.
 * (Licensed under the Synesis Software Standard Public License:
 *  http://www.synesis.com.au/licenses/ssspl.html)
 *
 * ...
 * ////////////////////////////////////////////////////////// */

SInt32 ListExchange_PutItems_Base(
        HWND                    hwndList,
        LPUNKNOWN               punkEnumItems,
        UInt32                  flags,
        UInt32                  param,
        EnumeratorHandler const *enumerators,
        UInt32                  cEnumerators,
        ControlHandler const    *controls,
        UInt32                  cControls)
{
  HRESULT hr;

  _ASSERTE(IsWindow(hwndList));

  if( !(flags & SYLXF_RESETCONTENT) &&
      ( NULL == punkEnumItems ||
        NULL == enumerators ||
        0 == cEnumerators))
  {
    hr = E_INVALIDARG;
  }
  else if(!IsWindow(hwndList) ||
          0 == cControls ||
          NULL == controls)
  {
    hr = E_INVALIDARG;
  }
  else
  {
    LPUNKNOWN punkEnum  = NULL;
    UInt32    i;

    /* Find the window class */
    for(hr = E_FAIL, i = 0; FAILED(hr) && i < cControls; ++i)
    {
      if(IsWindowClass(hwndList, controls[i].className))
      {
        hr = S_OK;
        break;
      }
    }

    if(FAILED(hr))
    {
      ErrorInfo_SetDescW(L"Window not of recognised class");

      hr = E_INVALIDARG;
    }
    else
    {
      ControlHandler const  *control  = &controls[i];

      if(NULL == punkEnumItems)
      {
        /* Only want to clear the window */

        _ASSERTE((flags & SYLXF_RESETCONTENT) == SYLXF_RESETCONTENT);

        control->pfnReset(hwndList);
      }
      else
      {
        /* Find the interface */
        for(hr = E_NOINTERFACE, i = 0; i < cEnumerators; ++i)
        {
#ifdef __cplusplus
          hr = punkEnumItems->QueryInterface(
#else
          hr = punkEnumItems->lpVtbl->QueryInterface( punkEnumItems,
#endif /* __cplusplus */
                                enumerators[i].iid,
                                (LPPVoid)(&punkEnum));

          if(SUCCEEDED(hr))
          {
            break;
          }
        }

        if(FAILED(hr))
        {
          ErrorInfo_SetDescW(L"Enumerator not of recognised type");

          hr = E_INVALIDARG;
        }
        else
        {
          EnumeratorHandler const *enumerator = &enumerators[i];

          /* Erase the existing content */
          if((flags & SYLXF_RESETCONTENT) == SYLXF_RESETCONTENT)
          {
            control->pfnReset(hwndList);
          }

          /* Now enumerate over the sequence, inserting as we go. */
          for(hr = S_OK, enumerator->pfnReset(punkEnum); SUCCEEDED(hr); )
          {
            Enum2WndItem  item;
            LPVOID      value;

            hr  = enumerator->pfnNextItem(punkEnum, &item, &value);

            if(hr == S_OK)
            {
              /* Add to the control ... */
              hr = control->pfnPutItem(hwndList, value, flags);

              /* ... and release any resources from enumerator */
              enumerator->pfnClearItem(punkEnum, &item, value);
            }
            else if(hr == S_FALSE)
            {
              hr = S_OK;
              break;
            }
          }

#ifdef __cplusplus
          punkEnum->Release();
#else
          punkEnum->lpVtbl->Release(punkEnum);
#endif /* __cplusplus */
        }
      }
    }
  }

  return hr;
}


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.