home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / olevar1.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  1KB  |  57 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef _DEBUG
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // new COleVariant code (uses new features of OLEAUT32.DLL)
  20.  
  21. COleVariant::COleVariant(LPCITEMIDLIST pidl)
  22. {
  23.     AfxVariantInit(this);
  24.  
  25.     if (pidl != NULL)
  26.     {
  27.         // walk through entries in the list and accumulate their size
  28.  
  29.         UINT cbTotal = 0;
  30.         SAFEARRAY *psa = NULL;
  31.         LPCITEMIDLIST pidlWalker = pidl;
  32.  
  33.         while (pidlWalker->mkid.cb)
  34.         {
  35.             cbTotal += pidlWalker->mkid.cb;
  36.             pidlWalker = (LPCITEMIDLIST)
  37.                 (((LPBYTE)pidlWalker) + pidlWalker->mkid.cb);
  38.         }
  39.  
  40.         // add the base structure size
  41.         cbTotal += sizeof(ITEMIDLIST);
  42.  
  43.         // get a safe array for them
  44.         psa = SafeArrayCreateVector(VT_UI1, 0, cbTotal);
  45.  
  46.         // copy it and set members
  47.         if (psa != NULL)
  48.         {
  49.             memcpy(psa->pvData, (LPBYTE) pidl, cbTotal);
  50.             vt = VT_ARRAY | VT_UI1;
  51.             parray = psa;
  52.         }
  53.     }
  54. }
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57.