Advertisement
Guest User

goto pattern with COM

a guest
Oct 30th, 2014
180
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void SomeFunction(IParent *pIParent)
  2. {
  3.     HRESULT hr;
  4.     IStuff *pIStuff1;
  5.     IStuff *pIStuff2;
  6.     IStuff *pIStuff3;
  7.  
  8.     pIStuff1 = NULL;
  9.     pIStuff2 = NULL;
  10.     pIStuff3 = NULL;
  11.  
  12.     hr = pIParent->QueryInterface(__uuidof(IStuff), (void **)&pIStuff1 );
  13.     if (FAILED(hr))
  14.         goto Done;
  15.  
  16.     hr = pIParent->QueryInterface(__uuidof(IStuff), (void **)&pIStuff2 );
  17.     if (FAILED(hr))
  18.         goto Done;
  19.  
  20.     hr = pIParent->QueryInterface(__uuidof(IStuff), (void **)&pIStuff3 );
  21.     if (FAILED(hr))
  22.         goto Done;
  23.  
  24. Done:
  25.     if (pIStuff1)
  26.     {
  27.         pIStuff1->Release();
  28.         pIStuff1 = NULL;
  29.     }
  30.     if (pIStuff2)
  31.     {
  32.         pIStuff2->Release();
  33.         pIStuff2 = NULL;
  34.     }
  35.     if (pIStuff3)
  36.     {
  37.         pIStuff3->Release();
  38.         pIStuff3 = NULL;
  39.     }
  40. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement