home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap03 / lst33 / lst33.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-19  |  3.7 KB  |  128 lines

  1. // lst33.cpp : Implementation of DLL Exports.
  2.  
  3. // To fully complete this project follow these steps
  4.  
  5. // You will need the new MIDL compiler to build this project.  Additionally,
  6. // if you are building the proxy stub DLL, you will need new headers and libs.
  7.  
  8. // 1) Add a custom build step to lst33.idl
  9. //        You can select all of the .IDL files by holding Ctrl and clicking on
  10. //        each of them.
  11. //
  12. //        Description
  13. //            Running MIDL
  14. //        Build Command(s)
  15. //            midl lst33.idl
  16. //        Outputs
  17. //            lst33.tlb
  18. //            lst33.h
  19. //            lst33_i.c
  20. //
  21. // NOTE: You must use the MIDL compiler from NT 4.0, 
  22. // preferably 3.00.15 or greater
  23.  
  24. // 2) Add a custom build step to the project to register the DLL
  25. //        For this, you can select all projects at once
  26. //        Description
  27. //            Registering OLE Server...
  28. //        Build Command(s)
  29. //            regsvr32 /s /c "$(TargetPath)"
  30. //            echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
  31. //        Outputs
  32. //            $(OutDir)\regsvr32.trg
  33.  
  34. // 3) To add UNICODE support, follow these steps
  35. //        Select Build|Configurations...
  36. //        Press Add...
  37. //        Change the configuration name to Unicode Release
  38. //        Change the "Copy Settings From" combo to lst33 - Win32 Release
  39. //        Press OK
  40. //        Press Add...
  41. //        Change the configuration name to Unicode Debug
  42. //        Change the "Copy Settings From" combo to lst33 - Win32 Debug
  43. //        Press OK
  44. //        Press "Close"
  45. //        Select Build|Settings...
  46. //        Select the two UNICODE projects and press the C++ tab.
  47. //        Select the "General" category
  48. //        Add _UNICODE to the Preprocessor definitions
  49. //        Select the Unicode Debug project
  50. //        Press the "General" tab
  51. //        Specify DebugU for the intermediate and output directories
  52. //        Select the Unicode Release project
  53. //        Press the "General" tab
  54. //        Specify ReleaseU for the intermediate and output directories
  55.  
  56. // 4) Proxy stub DLL
  57. //        To build a separate proxy/stub DLL, 
  58. //        run nmake -f ps.mak in the project directory.
  59.  
  60. #include "stdafx.h"
  61. #include "resource.h"
  62. #include "initguid.h"
  63. #include "lst33.h"
  64. #include "Lst33Obj.h"
  65.  
  66. #define IID_DEFINED
  67. #include "lst33_i.c"
  68.  
  69.  
  70. CComModule _Module;
  71.  
  72. BEGIN_OBJECT_MAP(ObjectMap)
  73.     OBJECT_ENTRY(CLSID_Lst33, CLst33Object, "LST33.Lst33Object.1", "LST33.Lst33Object.1", IDS_LST33_DESC, THREADFLAGS_BOTH)
  74. END_OBJECT_MAP()
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // DLL Entry Point
  78.  
  79. extern "C"
  80. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  81. {
  82.     if (dwReason == DLL_PROCESS_ATTACH)
  83.     {
  84.         _Module.Init(ObjectMap, hInstance);
  85.         DisableThreadLibraryCalls(hInstance);
  86.     }
  87.     else if (dwReason == DLL_PROCESS_DETACH)
  88.         _Module.Term();
  89.     return TRUE;    // ok
  90. }
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // Used to determine whether the DLL can be unloaded by OLE
  94.  
  95. STDAPI DllCanUnloadNow(void)
  96. {
  97.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  98. }
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // Returns a class factory to create an object of the requested type
  102.  
  103. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  104. {
  105.     return _Module.GetClassObject(rclsid, riid, ppv);
  106. }
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // DllRegisterServer - Adds entries to the system registry
  110.  
  111. STDAPI DllRegisterServer(void)
  112. {
  113.     HRESULT hRes = S_OK;
  114.     // registers object, typelib and all interfaces in typelib
  115.     hRes = _Module.UpdateRegistry(TRUE);
  116.     return hRes;
  117. }
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120. // DllUnregisterServer - Adds entries to the system registry
  121.  
  122. STDAPI DllUnregisterServer(void)
  123. {
  124.     HRESULT hRes = S_OK;
  125.     _Module.RemoveRegistry();
  126.     return hRes;
  127. }
  128.