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

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