home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / common / msdev98 / template / atl / aatldll.cpp next >
Encoding:
INI File  |  1998-06-16  |  2.9 KB  |  117 lines

  1. [!if=(InsertIntoInitInstance, "1")]
  2.     if (!InitATL())
  3.         return FALSE;
  4. [!endif]
  5.  
  6. [!if=(AddInitInstance, "1")]
  7.     if (!InitATL())
  8.         return FALSE;
  9. [!crlf]
  10.     return CWinApp::InitInstance();
  11. [!endif]
  12.  
  13. [!if(INITATL)]
  14.     _Module.Init(ObjectMap, AfxGetInstanceHandle());
  15.     return TRUE;
  16. [!endif]
  17.  
  18. [!if(InsertAfterApp)]
  19. [!crlf]
  20. CComModule _Module;
  21. [!crlf]
  22. BEGIN_OBJECT_MAP(ObjectMap)
  23. END_OBJECT_MAP()
  24. [!crlf]
  25. [!if=(MFCOLE, "0")]
  26. STDAPI DllCanUnloadNow(void)
  27. {
  28.     return (_Module.GetLockCount() == 0) ? S_OK : S_FALSE;
  29. }
  30. [!crlf]
  31. /////////////////////////////////////////////////////////////////////////////
  32. // Returns a class factory to create an object of the requested type
  33.  
  34. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  35. {
  36.     return _Module.GetClassObject(rclsid, riid, ppv);
  37. }
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // DllRegisterServer - Adds entries to the system registry
  41.  
  42. STDAPI DllRegisterServer(void)
  43. {
  44.     // registers object, typelib and all interfaces in typelib
  45.     return _Module.RegisterServer(TRUE);
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // DllUnregisterServer - Removes entries from the system registry
  50.  
  51. STDAPI DllUnregisterServer(void)
  52. {
  53.     _Module.UnregisterServer(TRUE); //TRUE indicates that typelib is unreg'd
  54.     return S_OK;
  55. }
  56. [!else]
  57. [!if=(MFCCTL, "1")]
  58. STDAPI DllCanUnloadNow(void)
  59. {
  60.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  61.     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  62. }
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // Returns a class factory to create an object of the requested type
  66.  
  67. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  68. {
  69.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  70.     if(AfxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  71.         return S_OK;
  72.     return _Module.GetClassObject(rclsid, riid, ppv);
  73. }
  74. [!else]
  75. STDAPI DllUnregisterServer(void)
  76. {
  77.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  78.  
  79.     if (!COleObjectFactoryEx::UpdateRegistryAll(FALSE))
  80.         return SELFREG_E_CLASS;
  81.  
  82.     _Module.UnregisterServer(TRUE); //TRUE indicates that typelib is unreg'd
  83.     return S_OK;
  84. }
  85. [!endif]
  86. [!endif]
  87. [!endif]
  88.  
  89. [!if=(InsertIntoExitInstance, "1")]
  90.     _Module.Term();
  91. [!crlf]
  92. [!endif]
  93.  
  94. [!if=(AddExitInstance, "1")]
  95.     _Module.Term();
  96. [!crlf]
  97.     return CWinApp::ExitInstance();
  98. [!endif]
  99.  
  100.  
  101. [!if=(InsertInDllRegisterServer, "1")]
  102.     return _Module.RegisterServer(TRUE);
  103. [!endif]
  104.  
  105. [!if=(InsertInDllUnregisterServer, "1")]
  106.     _Module.UnregisterServer(TRUE); //TRUE indicates that typelib is unreg'd
  107. [!endif]
  108.  
  109. [!if=(InsertInDllGetClassObject, "1")]
  110.     if (SUCCEEDED(_Module.GetClassObject(rclsid, riid, ppv)))
  111.         return S_OK;
  112. [!crlf]
  113. [!endif]
  114.  
  115. [!if=(InsertInDllCanUnloadNow, "1")]
  116.     return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  117. [!endif]