home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / com / labrador / labdriv / labdriv.cpp next >
C/C++ Source or Header  |  1998-04-02  |  2KB  |  90 lines

  1.  
  2. // labdriv.cpp : driver for the Labrador sample
  3. //
  4. // This is a part of the ActiveX Template Library.
  5. // Copyright (C) 1996 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // ActiveX Template Library Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // ActiveX Template Library product.
  13.  
  14. #include "prelabdr.h"
  15.  
  16. ///////////////////////////////////////////////////////////////
  17.  
  18. // helper to do print traces
  19. void _cdecl Trace(LPCTSTR lpszFormat, ...)
  20. {
  21.     va_list args;
  22.     va_start(args, lpszFormat);
  23.  
  24.     int nBuf;
  25.     TCHAR szBuffer[512];
  26.  
  27.     nBuf = _vstprintf(szBuffer, lpszFormat, args);
  28.     _ASSERTE(nBuf < sizeof(szBuffer));
  29.  
  30.     _tprintf(szBuffer);
  31.     OutputDebugString(szBuffer);
  32.     va_end(args);
  33. }
  34.  
  35. // helper function to do the work
  36. void _cdecl CallLabrador()
  37. {
  38.     USHORT szTmp[32];
  39.  
  40.     Trace(_T("\nSTARTING\n=============================\n"));
  41.     Trace(_T("Calling CoCreateInstance()...\n"));
  42.     IMammalPtr pMammal(__uuidof(Labrador));
  43.  
  44.     Trace(_T("Calling through IMammal methods...\n"));
  45.     pMammal->GetSpeciesName(szTmp);
  46.     Trace(_T("Species name is <%ls>\n"), szTmp);
  47.     LONG bIsAlive;
  48.     pMammal->IsAlive(&bIsAlive);
  49.     if (bIsAlive)
  50.         Trace(_T("And it's alive!\n"));
  51.     else
  52.         Trace(_T("And it's dead!\n"));
  53.  
  54.     IDogPtr pDog = pMammal;
  55.  
  56.     Trace(_T("Calling through IDog methods...\n"));
  57.     LONG bIsBarking;
  58.     pDog->GetPetName(szTmp);
  59.     Trace(_T("Dog's name is <%ls>\n"), szTmp);
  60.  
  61.     pDog->IsBarking(&bIsBarking);
  62.     if (bIsBarking)
  63.         printf("BARK! BARK! BARK! BARK!\n");
  64.  
  65.     pDog->SetPetName(L"KIVA");
  66.  
  67.     pDog->GetPetName(szTmp);
  68.     printf("Dog's New name is <%ls>\n", szTmp);
  69.  
  70.     Trace(_T("Releasing Objects\n"));
  71.     pDog = 0;
  72.     pMammal = 0;
  73.     Trace(_T("\nDONE!!!\n=============================\n"));
  74. }
  75.  
  76. int main( int argc, char *argv[ ])
  77. {
  78.  
  79.     if (FAILED(CoInitialize(NULL)))
  80.         return -1;
  81.  
  82.     CallLabrador();
  83.  
  84. #ifdef _DEBUG
  85.     _CrtDumpMemoryLeaks();
  86. #endif
  87.     CoUninitialize();
  88.     return 0;
  89. }
  90.