home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap04 / lst42 / lst42doc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-26  |  3.2 KB  |  139 lines

  1. // lst42Doc.cpp : implementation of the CLst42Doc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "lst42.h"
  6.  
  7. #include "lst42Doc.h"
  8. #include "SrvrItem.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CLst42Doc
  18.  
  19. IMPLEMENT_DYNCREATE(CLst42Doc, COleServerDoc)
  20.  
  21. BEGIN_MESSAGE_MAP(CLst42Doc, COleServerDoc)
  22.     //{{AFX_MSG_MAP(CLst42Doc)
  23.         // NOTE - the ClassWizard will add and remove mapping macros here.
  24.         //    DO NOT EDIT what you see in these blocks of generated code!
  25.     //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27.  
  28. BEGIN_DISPATCH_MAP(CLst42Doc, COleServerDoc)
  29.     //{{AFX_DISPATCH_MAP(CLst42Doc)
  30.     DISP_FUNCTION(CLst42Doc, "GetMachineName", GetMachineName, VT_BSTR, VTS_NONE)
  31.     //}}AFX_DISPATCH_MAP
  32. END_DISPATCH_MAP()
  33.  
  34. // Note: we add support for IID_ILst42 to support typesafe binding
  35. //  from VBA.  This IID must match the GUID that is attached to the 
  36. //  dispinterface in the .ODL file.
  37.  
  38. // {06B70DA2-1818-11D0-A6AD-00AA00602553}
  39. static const IID IID_ILst42 =
  40. { 0x6b70da2, 0x1818, 0x11d0, { 0xa6, 0xad, 0x0, 0xaa, 0x0, 0x60, 0x25, 0x53 } };
  41.  
  42. BEGIN_INTERFACE_MAP(CLst42Doc, COleServerDoc)
  43.     INTERFACE_PART(CLst42Doc, IID_ILst42, Dispatch)
  44. END_INTERFACE_MAP()
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CLst42Doc construction/destruction
  48.  
  49. CLst42Doc::CLst42Doc()
  50. {
  51.     // Use OLE compound files
  52.     EnableCompoundFile();
  53.  
  54.     // TODO: add one-time construction code here
  55.  
  56.     EnableAutomation();
  57.  
  58.     AfxOleLockApp();
  59. }
  60.  
  61. CLst42Doc::~CLst42Doc()
  62. {
  63.     AfxOleUnlockApp();
  64. }
  65.  
  66. BOOL CLst42Doc::OnNewDocument()
  67. {
  68.     if (!COleServerDoc::OnNewDocument())
  69.         return FALSE;
  70.  
  71.     // TODO: add reinitialization code here
  72.     // (SDI documents will reuse this document)
  73.  
  74.     return TRUE;
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CLst42Doc server implementation
  79.  
  80. COleServerItem* CLst42Doc::OnGetEmbeddedItem()
  81. {
  82.     // OnGetEmbeddedItem is called by the framework to get the COleServerItem
  83.     //  that is associated with the document.  It is only called when necessary.
  84.  
  85.     CLst42SrvrItem* pItem = new CLst42SrvrItem(this);
  86.     ASSERT_VALID(pItem);
  87.     return pItem;
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CLst42Doc serialization
  92.  
  93. void CLst42Doc::Serialize(CArchive& ar)
  94. {
  95.     if (ar.IsStoring())
  96.     {
  97.         // TODO: add storing code here
  98.     }
  99.     else
  100.     {
  101.         // TODO: add loading code here
  102.     }
  103. }
  104.  
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CLst42Doc diagnostics
  107.  
  108. #ifdef _DEBUG
  109. void CLst42Doc::AssertValid() const
  110. {
  111.     COleServerDoc::AssertValid();
  112. }
  113.  
  114. void CLst42Doc::Dump(CDumpContext& dc) const
  115. {
  116.     COleServerDoc::Dump(dc);
  117. }
  118. #endif //_DEBUG
  119.  
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CLst42Doc commands
  122.  
  123. BSTR CLst42Doc::GetMachineName() 
  124. {
  125.     CString strResult;
  126.     ULONG ulLen;
  127.  
  128.     char *lpName;
  129.  
  130.     lpName = new char[MAX_PATH];
  131.     ulLen = MAX_PATH;
  132.  
  133.     GetComputerName(lpName, &ulLen );
  134.     strResult = lpName;
  135.     delete [] lpName;
  136.  
  137.     return strResult.AllocSysString();
  138. }
  139.