kernel.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // kernel.cpp : Defines the initialization routines for the DLL.
  2. //
  3. #include "stdafx.h"
  4. #include <afxdllx.h>
  5. #include "kernel.h"
  6. #include "SocketHandle.h"
  7. //#include "database.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. AFX_EXTENSION_MODULE KernelDLL = { NULL, NULL };
  14. extern "C" int APIENTRY
  15. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  16. {
  17. // Remove this if you use lpReserved
  18. UNREFERENCED_PARAMETER(lpReserved);
  19. if (dwReason == DLL_PROCESS_ATTACH)
  20. {
  21. TRACE0("KERNEL.DLL Initializing!\n");
  22. // Extension DLL one-time initialization
  23. if (!AfxInitExtensionModule(KernelDLL, hInstance))
  24. return 0;
  25. // Insert this DLL into the resource chain
  26. // NOTE: If this Extension DLL is being implicitly linked to by
  27. // an MFC Regular DLL (such as an ActiveX Control)
  28. // instead of an MFC application, then you will want to
  29. // remove this line from DllMain and put it in a separate
  30. // function exported from this Extension DLL. The Regular DLL
  31. // that uses this Extension DLL should then explicitly call that
  32. // function to initialize this Extension DLL. Otherwise,
  33. // the CDynLinkLibrary object will not be attached to the
  34. // Regular DLL's resource chain, and serious problems will
  35. // result.
  36. new CDynLinkLibrary(KernelDLL);
  37. }
  38. else if (dwReason == DLL_PROCESS_DETACH)
  39. {
  40. TRACE0("KERNEL.DLL Terminating!\n");
  41. // Terminate the library before destructors are called
  42. AfxTermExtensionModule(KernelDLL);
  43. }
  44. OleInitialize(NULL);
  45. return 1; // ok
  46. }
  47. CDevicesManager* pDevicesManager = NULL;
  48. CVariantsManager* pVariantsManager = NULL;
  49. CEventServer* pEventServer = NULL;
  50. void CreateSystem(void)
  51. {
  52. if (pVariantsManager == NULL)
  53. {
  54. pVariantsManager = new CVariantsManager;
  55. }
  56. // 初始化客户端SOCKET库;
  57. CSocketHandle::InitLibrary( MAKEWORD(2,2) );
  58. }
  59. void DestroySystem(void)
  60. {
  61. if (pVariantsManager != NULL)
  62. {
  63. delete pVariantsManager;
  64. }
  65. // 释放客户端SOCKET库;
  66. CSocketHandle::ReleaseLibrary();
  67. }