Advertisement
bkuhns

Before/After SafeArrayPtr

Oct 11th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. /**
  2.  * SAFEARRAY* "before"...
  3.  */
  4. void before() {
  5.     CSafeArrayHolder saLinesArray;
  6.     HRESULT hr;
  7.     LONG idx;
  8.     IUnknown* pUNK;
  9.     _bstr_t b_str;
  10.     LONG UBound = 0;
  11.  
  12.     saLinesArray.AttachSafeArray(spIMaster->GetLines());
  13.  
  14.     // Arrays are zero-based. No need to get LBound
  15.     hr = SafeArrayGetUBound( saLinesArray, 1, &UBound);
  16.     if (FAILED(hr))
  17.     {
  18.         b_str = L"SafeArrayGetUBound in GetLine failed";
  19.         throw SyncMgrEx(b_str.GetBSTR());
  20.     }
  21.  
  22.     // Currently only one line is supported
  23.     if ((UBound + 1) != 1)
  24.     {
  25.         b_str = L"Only one line per Master is supported";
  26.         throw SyncMgrEx(b_str.GetBSTR());
  27.     }
  28.  
  29.     for (idx = 0; idx < (UBound + 1) ; idx++)
  30.     {
  31.         hr = SafeArrayGetElement(   saLinesArray,
  32.                                     &idx,
  33.                                     reinterpret_cast<void*>(&pUNK));
  34.         spILine = pUNK;
  35.         if (spILine.GetInterfacePtr() == NULL)
  36.         {
  37.             b_str = L"Unexpected interface in GetLine";
  38.             throw SyncMgrEx(b_str.GetBSTR());
  39.         }
  40.  
  41.     }
  42. }
  43.  
  44.  
  45. /**
  46.  * SafeArrayPtr "after"...
  47.  */
  48. void after()
  49. {
  50.     SafeArrayPtr<ILinePtr> lines = master->GetLines();
  51.     if(lines.size() != 1) {
  52.         ASSERT(false);  //< We only support one line at the moment.
  53.         return nullptr;
  54.     }
  55.     auto line = lines.at(0);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement