USBUpgradeDLL.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "stdafx.h"
  2. #include "USBUpgradeDLL.h"
  3. namespace USBUPGRADE {
  4. HMODULE g_hdll = NULL;
  5. OPEN_TVPORT OpenTVPort = NULL;
  6. IS_OPEN IsOpen = NULL;
  7. CLOSE_TVPORT CloseTVPort = NULL;
  8. START_MONITOR StartMonitor = NULL;
  9. SEND_COMMAND SendCommand = NULL;
  10. CLEARBUFFER ClearBuffer = NULL;
  11. WATCH_WORD WatchWord = NULL;
  12. RTK_UPBUPGRADE RTK_USBUpgrade = NULL;
  13. BOOL LoadLibrary()
  14. {
  15. if (g_hdll == NULL) {
  16. g_hdll = (HMODULE)::LoadLibrary(_T("SerialWatch.dll"));
  17. if (!g_hdll)
  18. return FALSE;
  19. }
  20. OpenTVPort = (OPEN_TVPORT)GetProcAddress(g_hdll, "OpenTVPort");
  21. if (!OpenTVPort)
  22. {
  23. UnloadLibrary();
  24. return FALSE;
  25. }
  26. IsOpen = (IS_OPEN)GetProcAddress(g_hdll, "IsOpen");
  27. if (!IsOpen)
  28. {
  29. UnloadLibrary();
  30. return FALSE;
  31. }
  32. CloseTVPort = (CLOSE_TVPORT)GetProcAddress(g_hdll, "CloseTVPort");
  33. if (!CloseTVPort)
  34. {
  35. UnloadLibrary();
  36. return FALSE;
  37. }
  38. StartMonitor = (START_MONITOR)GetProcAddress(g_hdll, "StartMonitor");
  39. if (!StartMonitor)
  40. {
  41. UnloadLibrary();
  42. return FALSE;
  43. }
  44. SendCommand = (SEND_COMMAND)GetProcAddress(g_hdll, "SendCommand");
  45. if (!SendCommand)
  46. {
  47. UnloadLibrary();
  48. return FALSE;
  49. }
  50. ClearBuffer = (CLEARBUFFER)GetProcAddress(g_hdll, "ClearBuffer");
  51. if (!ClearBuffer)
  52. {
  53. UnloadLibrary();
  54. return FALSE;
  55. }
  56. WatchWord = (WATCH_WORD)GetProcAddress(g_hdll, "WatchWord");
  57. if (!WatchWord)
  58. {
  59. UnloadLibrary();
  60. return FALSE;
  61. }
  62. RTK_USBUpgrade = (RTK_UPBUPGRADE)GetProcAddress(g_hdll, "RTK_USBUpgrade");
  63. if (!RTK_USBUpgrade)
  64. {
  65. UnloadLibrary();
  66. return FALSE;
  67. }
  68. return TRUE;
  69. }
  70. void UnloadLibrary()
  71. {
  72. if (g_hdll) {
  73. if (FreeLibrary(g_hdll)) {
  74. g_hdll = NULL;
  75. OpenTVPort = NULL;
  76. IsOpen = NULL;
  77. CloseTVPort = NULL;
  78. StartMonitor = NULL;
  79. SendCommand = NULL;
  80. ClearBuffer = NULL;
  81. WatchWord = NULL;
  82. RTK_USBUpgrade = NULL;
  83. }
  84. }
  85. }
  86. void RTKUpgrade(int nKeyType)
  87. {
  88. std::thread t([](int keyType) {
  89. if (RTK_USBUpgrade)
  90. RTK_USBUpgrade(keyType);
  91. OutputDebugString("Í˳öË¢ÐÂÉ豸Ïß³Ì\n");
  92. }, nKeyType);
  93. t.detach();
  94. }
  95. }