home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / minimal / mindriv / mindriv.cpp next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  87 lines

  1.  
  2. // mindriv.cpp : driver for the Minimal 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 "premindr.h"
  15. #include <initguid.h>
  16. #include "..\\minimal.h"
  17.  
  18.  
  19. ///////////////////////////////////////////////////////////////
  20.  
  21. // helper to do print traces
  22. void _cdecl Trace(LPCTSTR lpszFormat, ...)
  23. {
  24.     va_list args;
  25.     va_start(args, lpszFormat);
  26.  
  27.     int nBuf;
  28.     TCHAR szBuffer[512];
  29.  
  30.     nBuf = _vstprintf(szBuffer, lpszFormat, args);
  31.     _ASSERT(nBuf < sizeof(szBuffer));
  32.  
  33.     _tprintf(szBuffer);
  34.     OutputDebugString(szBuffer);
  35.     va_end(args);
  36. }
  37.  
  38. // helper function to do the work
  39. void _cdecl CallMinimal()
  40. {
  41.     Trace(_T("\nSTARTING\n=============================\n"));
  42.     Trace(_T("Calling CoCreateInstance()...\n"));
  43.     IUnknown* pUnk = NULL;
  44.     HRESULT hRes = CoCreateInstance(CLSID_CMinObj, NULL, CLSCTX_INPROC_SERVER,
  45.         IID_IUnknown, (void**)&pUnk);
  46.     if (FAILED(hRes))
  47.     {
  48.         Trace(_T("Failed to create MinObj\n"));
  49.         return;
  50.     }
  51.     Trace(_T("Object created\n"));
  52.  
  53.     IMinObj* pMin = NULL;
  54.     hRes = pUnk->QueryInterface(IID_IMinObj, (LPVOID*)&pMin);
  55.     pUnk->Release();
  56.     if (FAILED(hRes))
  57.     {
  58.         Trace(_T("QueryInterface() for IMinObj failed\n"));
  59.         return;
  60.     }
  61.  
  62.     Trace(_T("Calling IMinObj::Hello() method...\n"));
  63.     hRes = pMin->Hello();
  64.     if (SUCCEEDED(hRes))
  65.         Trace(_T("Call succeeded\n"));
  66.     else
  67.         Trace(_T("Call failed\n"));
  68.     Trace(_T("Releasing Object\n"));
  69.     pMin->Release();
  70.     Trace(_T("\nDONE!!!\n=============================\n"));
  71. }
  72.  
  73. int main( int argc, char *argv[ ])
  74. {
  75.  
  76.     if (FAILED(CoInitialize(NULL)))
  77.         return -1;
  78.  
  79.     CallMinimal();
  80.  
  81. #ifdef _DEBUG
  82.     _CrtDumpMemoryLeaks();
  83. #endif
  84.     CoUninitialize();
  85.     return 0;
  86. }
  87.