123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include "stdafx.h"
- #include "USBUpgradeDLL.h"
- namespace USBUPGRADE {
- HMODULE g_hdll = NULL;
- OPEN_TVPORT OpenTVPort = NULL;
- IS_OPEN IsOpen = NULL;
- CLOSE_TVPORT CloseTVPort = NULL;
- START_MONITOR StartMonitor = NULL;
- SEND_COMMAND SendCommand = NULL;
- CLEARBUFFER ClearBuffer = NULL;
- WATCH_WORD WatchWord = NULL;
- RTK_UPBUPGRADE RTK_USBUpgrade = NULL;
- BOOL LoadLibrary()
- {
- if (g_hdll == NULL) {
- g_hdll = (HMODULE)::LoadLibrary(_T("SerialWatch.dll"));
- if (!g_hdll)
- return FALSE;
- }
- OpenTVPort = (OPEN_TVPORT)GetProcAddress(g_hdll, "OpenTVPort");
- if (!OpenTVPort)
- {
- UnloadLibrary();
- return FALSE;
- }
- IsOpen = (IS_OPEN)GetProcAddress(g_hdll, "IsOpen");
- if (!IsOpen)
- {
- UnloadLibrary();
- return FALSE;
- }
- CloseTVPort = (CLOSE_TVPORT)GetProcAddress(g_hdll, "CloseTVPort");
- if (!CloseTVPort)
- {
- UnloadLibrary();
- return FALSE;
- }
- StartMonitor = (START_MONITOR)GetProcAddress(g_hdll, "StartMonitor");
- if (!StartMonitor)
- {
- UnloadLibrary();
- return FALSE;
- }
- SendCommand = (SEND_COMMAND)GetProcAddress(g_hdll, "SendCommand");
- if (!SendCommand)
- {
- UnloadLibrary();
- return FALSE;
- }
- ClearBuffer = (CLEARBUFFER)GetProcAddress(g_hdll, "ClearBuffer");
- if (!ClearBuffer)
- {
- UnloadLibrary();
- return FALSE;
- }
- WatchWord = (WATCH_WORD)GetProcAddress(g_hdll, "WatchWord");
- if (!WatchWord)
- {
- UnloadLibrary();
- return FALSE;
- }
- RTK_USBUpgrade = (RTK_UPBUPGRADE)GetProcAddress(g_hdll, "RTK_USBUpgrade");
- if (!RTK_USBUpgrade)
- {
- UnloadLibrary();
- return FALSE;
- }
- return TRUE;
- }
- void UnloadLibrary()
- {
- if (g_hdll) {
- if (FreeLibrary(g_hdll)) {
- g_hdll = NULL;
- OpenTVPort = NULL;
- IsOpen = NULL;
- CloseTVPort = NULL;
- StartMonitor = NULL;
- SendCommand = NULL;
- ClearBuffer = NULL;
- WatchWord = NULL;
- RTK_USBUpgrade = NULL;
- }
- }
- }
- void RTKUpgrade(int nKeyType)
- {
- std::thread t([](int keyType) {
- if (RTK_USBUpgrade)
- RTK_USBUpgrade(keyType);
- OutputDebugString("Í˳öË¢ÐÂÉ豸Ïß³Ì\n");
- }, nKeyType);
- t.detach();
- }
- }
|