home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / APTSERVE / SERVER.H < prev    next >
C/C++ Source or Header  |  1996-12-29  |  4KB  |  128 lines

  1. /*+==========================================================================
  2.   File:      SERVER.H
  3.  
  4.   Summary:   Internal include file for the APTSERVE.EXE local server code
  5.              sample.  Contains class declarations, resource IDs and string
  6.              macros for internal use in constructing this EXE as a local
  7.              COM component server using Apartment model multi-threading.
  8.              Declares the CServer server control object class.
  9.  
  10.              For a comprehensive tutorial code tour of this module's
  11.              contents and offerings see the tutorial APTSERVE.HTM file.
  12.              For more specific technical details on the internal workings
  13.              see the comments dispersed throughout the module's source code.
  14.  
  15.   Classes:   CServer.
  16.  
  17.   Functions: none
  18.  
  19.   Origin:    3-20-96: atrent - Editor-inheritance from SERVER.H in
  20.                the LOCSERVE Tutorial Code Sample.
  21.  
  22. ----------------------------------------------------------------------------
  23.   This file is part of the Microsoft ActiveX Tutorial Code Samples.
  24.  
  25.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  26.  
  27.   This source code is intended only as a supplement to Microsoft
  28.   Development Tools and/or on-line documentation.  See these other
  29.   materials for detailed information regarding Microsoft code samples.
  30.  
  31.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  32.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  33.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  34.   PARTICULAR PURPOSE.
  35. ==========================================================================+*/
  36.  
  37.  
  38. #if !defined(SERVER_H)
  39. #define SERVER_H
  40.  
  41. #ifdef __cplusplus
  42.  
  43. // Appartment Thread Initialization data.
  44. enum { NUM_APARTMENTS = 3 };
  45. enum { APTCAR = 0, APTUTILITYCAR = 1, APTCRUISECAR = 2 };
  46. struct APT_INIT_DATA
  47. {
  48.   REFCLSID rclsid;
  49.   IUnknown* pcf;
  50.  
  51.   // Member initializer MUST be used here because VC++ 4.0+ is strict
  52.   // about const and reference (&) types like REFCLSID that need to
  53.   // be initialized in this app.  For example, VC++ 4.x will not permit
  54.   // a simple assignment of rclsid in the constructor.
  55.   APT_INIT_DATA(REFCLSID rclsidi) : rclsid(rclsidi)
  56.   {
  57.     pcf = NULL;
  58.   };
  59.  
  60.   ~APT_INIT_DATA() {};
  61. };
  62.  
  63.  
  64. /*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C
  65.   Class:    CServer
  66.  
  67.   Summary:  Class to encapsulate control of this COM server (eg, handle
  68.             Lock and Object counting, encapsulate otherwise global data).
  69.             Govern server and Apartment lifetimes.
  70.  
  71.   Methods:  none
  72. C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/
  73. class CServer : public CThreaded
  74. {
  75.   public:
  76.     CServer(void);
  77.     ~CServer(void);
  78.  
  79.     void Lock(void);
  80.     void Unlock(void);
  81.     void ObjectsUp(void);
  82.     void ObjectsDown(void);
  83.     BOOL OpenFactories(void);
  84.     BOOL CloseFactories(void);
  85.  
  86.     // CThreaded method overrides.
  87.     BOOL OwnThis(void);
  88.     void UnOwnThis(void);
  89.  
  90.     // A place to store the server's instance handle.
  91.     HINSTANCE m_hInstServer;
  92.  
  93.     // A place to store the server's main window.
  94.     HINSTANCE m_hWndServer;
  95.  
  96.     // Global Server living Object count.
  97.     LONG      m_cObjects;
  98.  
  99.     // Global Server Client Lock count.
  100.     LONG      m_cLocks;
  101.  
  102.     // Some member variables to store pointers to Class Factories.
  103.     IUnknown* m_pCFCar;
  104.     IUnknown* m_pCFUtilityCar;
  105.     IUnknown* m_pCFCruiseCar;
  106.  
  107.     // Pointers to Apartment init data structures.
  108.     APT_INIT_DATA* m_paiAptCar;
  109.     APT_INIT_DATA* m_paiAptUtilityCar;
  110.     APT_INIT_DATA* m_paiAptCruiseCar;
  111.  
  112.     // Some member variables to store apartment thread ids.
  113.     DWORD     m_dwAptCar;
  114.     DWORD     m_dwAptUtilityCar;
  115.     DWORD     m_dwAptCruiseCar;
  116.  
  117.     // An array of handles to the apartment threads.
  118.     HANDLE    m_hApts[NUM_APARTMENTS];
  119. };
  120.  
  121. #endif // __cplusplus
  122.  
  123. // Allow other internal APTSERVE modules to get at the globals.
  124. extern CServer*  g_pServer;
  125. extern CSendLog* g_pMsgLog;
  126.  
  127. #endif // SERVER_H
  128.