Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.3 KiB

  1. /*
  2. * MAIN.CPP
  3. *
  4. *
  5. *
  6. *
  7. *
  8. *
  9. */
  10. #include <windows.h>
  11. #include <hidclass.h>
  12. #include <hidsdi.h>
  13. #include <ole2.h>
  14. #include <ole2ver.h>
  15. #include "..\inc\opos.h"
  16. #include "oposserv.h"
  17. COPOSService *g_oposService = NULL;
  18. DWORD g_classObjId = 0;
  19. /*
  20. ************************************************************
  21. * DllMain
  22. ************************************************************
  23. *
  24. *
  25. */
  26. STDAPI_(BOOL) DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID lpReserved)
  27. {
  28. static BOOLEAN serverInitialized = FALSE;
  29. BOOLEAN result;
  30. switch (dwReason){
  31. case DLL_PROCESS_ATTACH:
  32. Report("DllMain: DLL_PROCESS_ATTACH", dwReason); // BUGBUG REMOVE
  33. ASSERT(!serverInitialized);
  34. result = serverInitialized = InitServer();
  35. ASSERT(result);
  36. break;
  37. case DLL_PROCESS_DETACH:
  38. Report("DllMain: DLL_PROCESS_DETACH", dwReason); // BUGBUG REMOVE
  39. ASSERT(serverInitialized);
  40. ShutdownServer();
  41. serverInitialized = FALSE;
  42. result = TRUE;
  43. break;
  44. case DLL_THREAD_ATTACH:
  45. Report("DllMain: DLL_THREAD_ATTACH", dwReason); // BUGBUG REMOVE
  46. result = TRUE;
  47. break;
  48. case DLL_THREAD_DETACH:
  49. Report("DllMain: DLL_THREAD_DETACH", dwReason); // BUGBUG REMOVE
  50. result = TRUE;
  51. break;
  52. default:
  53. Report("DllMain", dwReason); // BUGBUG REMOVE
  54. result = TRUE;
  55. break;
  56. }
  57. return result;
  58. }
  59. /*
  60. ************************************************************
  61. * InitServer
  62. ************************************************************
  63. *
  64. * Register the server GUID with the OLE library,
  65. * making it possible for POS control objects
  66. * to open server instances.
  67. *
  68. */
  69. BOOLEAN InitServer()
  70. {
  71. BOOLEAN result = FALSE;
  72. HRESULT hres;
  73. hres = OleInitialize(NULL);
  74. if ((hres == S_OK) || (hres == S_FALSE)){
  75. Report("Ole is initialized", (DWORD)hres);
  76. g_oposService = new COPOSService;
  77. if (g_oposService){
  78. hres = CoRegisterClassObject(
  79. GUID_HID_OPOS_SERVER,
  80. (IUnknown *)g_oposService,
  81. CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER,
  82. REGCLS_MULTIPLEUSE , // BUGBUG ? REGCLS_SINGLEUSE,
  83. &g_classObjId);
  84. if ((hres == S_OK) || (hres == CO_E_OBJISREG)){
  85. Report("Registered Server", (DWORD)hres);
  86. result = TRUE;
  87. }
  88. else {
  89. Report("CoRegisterClassObject failed", (DWORD)hres);
  90. }
  91. if (!result){
  92. delete g_oposService;
  93. }
  94. }
  95. else {
  96. Report("Couldn't create COPOSService instance", 0);
  97. }
  98. }
  99. else {
  100. Report("OleInitialize failed", (DWORD)hres);
  101. }
  102. return result;
  103. }
  104. /*
  105. ************************************************************
  106. * ShutdownServer
  107. ************************************************************
  108. *
  109. *
  110. */
  111. void ShutdownServer()
  112. {
  113. Report("ShutdownServer", 0);
  114. CoRevokeClassObject(g_classObjId);
  115. if (g_oposService){
  116. delete g_oposService;
  117. g_oposService = NULL;
  118. }
  119. OleUninitialize();
  120. }