[363] | 1 | /*
|
---|
| 2 | * TOPPERS/JSP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Just Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | *
|
---|
| 9 | * ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 11 | * ã«ãã£ã¦å
|
---|
| 12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 15 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 21 | * ç¨ã§ããå½¢ã§åé
|
---|
| 22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 24 | * è
|
---|
| 25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 30 | * ã¨ï¼
|
---|
| 31 | * (a) åé
|
---|
| 32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 34 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 35 | * (b) åé
|
---|
| 36 | å¸ã®å½¢æ
|
---|
| 37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 38 | * å ±åãããã¨ï¼
|
---|
| 39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 40 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | *
|
---|
| 44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ã
|
---|
| 46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: devicemanager.cpp,v 1.11 2003/12/24 07:40:42 takayuki Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | #include "stdafx.h"
|
---|
| 54 | #include "resource.h"
|
---|
| 55 | #include <initguid.h>
|
---|
| 56 | #include <shellapi.h>
|
---|
| 57 | #include "devicemanager.h"
|
---|
| 58 | #include <commctrl.h>
|
---|
| 59 |
|
---|
| 60 | #include "devicemanager_i.c"
|
---|
| 61 | #include "device.h"
|
---|
| 62 | #include "information.h"
|
---|
| 63 | #include "kernel.h"
|
---|
| 64 | #include "kernellog.h"
|
---|
| 65 |
|
---|
| 66 | #define WM_NOTIFYICONCALLBACK (WM_APP+1) //NotifyIconããåãåãã¡ãã»ã¼ã¸ã«ä½¿ãçªå·
|
---|
| 67 |
|
---|
| 68 | const DWORD dwTimeOut = 5000; // EXEãã·ã£ãããã¦ã³ããã¾ã§ã®ã¢ã¤ãã«æéã§ã
|
---|
| 69 | const DWORD dwPause = 1000; // ã¹ã¬ãããçµããã®ãå¾
|
---|
| 70 | ã¤æéã§ã
|
---|
| 71 |
|
---|
| 72 | HINSTANCE ProcessInstance = NULL; //ããã»ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãã³ãã«
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | // ã·ã£ãããã¦ã³ ã¤ãã³ãç£è¦ç¨ã® CreateThread ã«æ¸¡ããã¾ã
|
---|
| 76 | static DWORD WINAPI MonitorProc(void* pv)
|
---|
| 77 | {
|
---|
| 78 | CExeModule* p = (CExeModule*)pv;
|
---|
| 79 | p->MonitorShutdown();
|
---|
| 80 | return 0;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | LONG CExeModule::Unlock()
|
---|
| 84 | {
|
---|
| 85 | LONG l = CComModule::Unlock();
|
---|
| 86 | if (l == 0)
|
---|
| 87 | {
|
---|
| 88 | bActivity = true;
|
---|
| 89 | SetEvent(hEventShutdown); // ã¢ãã¿ã¼ã«ã¼ãã«å¤ç§»ãããã¨ããããã¾ã
|
---|
| 90 | }
|
---|
| 91 | return l;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | //ã·ã£ãããã¦ã³ã¤ãã³ããç£è¦ãã¾ã
|
---|
| 95 | void CExeModule::MonitorShutdown()
|
---|
| 96 | {
|
---|
| 97 | while (1)
|
---|
| 98 | {
|
---|
| 99 | WaitForSingleObject(hEventShutdown, INFINITE);
|
---|
| 100 | DWORD dwWait=0;
|
---|
| 101 | do
|
---|
| 102 | {
|
---|
| 103 | bActivity = false;
|
---|
| 104 | dwWait = WaitForSingleObject(hEventShutdown, dwTimeOut);
|
---|
| 105 | } while (dwWait == WAIT_OBJECT_0);
|
---|
| 106 | // timed out
|
---|
| 107 | if (!bActivity && m_nLockCnt == 0) // ä½ãåä½ãã¦ãããã®ããªããã°æãåºãã¾ã
|
---|
| 108 | {
|
---|
| 109 | #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
|
---|
| 110 | CoSuspendClassObjects();
|
---|
| 111 | if (!bActivity && m_nLockCnt == 0)
|
---|
| 112 | #endif
|
---|
| 113 | break;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 | CloseHandle(hEventShutdown);
|
---|
| 117 | PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | bool CExeModule::StartMonitor()
|
---|
| 121 | {
|
---|
| 122 | hEventShutdown = CreateEvent(NULL, false, false, NULL);
|
---|
| 123 | if (hEventShutdown == NULL)
|
---|
| 124 | return false;
|
---|
| 125 | DWORD dwThreadID;
|
---|
| 126 | HANDLE h = CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID);
|
---|
| 127 | return (h != NULL);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | CExeModule _Module;
|
---|
| 131 |
|
---|
| 132 | BEGIN_OBJECT_MAP(ObjectMap)
|
---|
| 133 | OBJECT_ENTRY(CLSID_Device, CDevice)
|
---|
| 134 | OBJECT_ENTRY(CLSID_Information, CInformation)
|
---|
| 135 | OBJECT_ENTRY(CLSID_Kernel, CKernel)
|
---|
| 136 | OBJECT_ENTRY(CLSID_KernelLog, CKernelLog)
|
---|
| 137 | END_OBJECT_MAP()
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
|
---|
| 141 | {
|
---|
| 142 | while (p1 != NULL && *p1 != NULL)
|
---|
| 143 | {
|
---|
| 144 | LPCTSTR p = p2;
|
---|
| 145 | while (p != NULL && *p != NULL)
|
---|
| 146 | {
|
---|
| 147 | if (*p1 == *p)
|
---|
| 148 | return CharNext(p1);
|
---|
| 149 | p = CharNext(p);
|
---|
| 150 | }
|
---|
| 151 | p1 = CharNext(p1);
|
---|
| 152 | }
|
---|
| 153 | return NULL;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | static void InsertAllDeviceMapList(HWND hList)
|
---|
| 157 | {
|
---|
| 158 | _TCHAR buffer[64];
|
---|
| 159 | std::map<Range, class CDevice *>::iterator scope;
|
---|
| 160 | LVITEM item;
|
---|
| 161 | int index;
|
---|
| 162 | int length = 0;
|
---|
| 163 |
|
---|
| 164 | ListView_DeleteAllItems(hList);
|
---|
| 165 | item.iItem = -1;
|
---|
| 166 |
|
---|
| 167 | EnterCriticalSection(&_Module.cs);
|
---|
| 168 |
|
---|
| 169 | scope = _Module.DeviceMap.begin();
|
---|
| 170 | while(scope != _Module.DeviceMap.end()) {
|
---|
| 171 | _TCHAR * strbuf = (_TCHAR *)(BSTR)scope->second->DeviceName;
|
---|
| 172 |
|
---|
| 173 | #ifndef _UNICODE
|
---|
| 174 | length = WideCharToMultiByte(CP_ACP, 0, (BSTR)scope->second->DeviceName, -1, 0, 0, NULL, NULL);
|
---|
| 175 | if(length != 0) {
|
---|
| 176 | strbuf = new _TCHAR [length + 1];
|
---|
| 177 | WideCharToMultiByte(CP_ACP, 0, (BSTR)scope->second->DeviceName, length, (char *)strbuf, length, NULL, NULL);
|
---|
| 178 | }
|
---|
| 179 | else
|
---|
| 180 | strbuf = _T("<unknown>");
|
---|
| 181 | #endif
|
---|
| 182 |
|
---|
| 183 | item.mask = LVIF_TEXT;
|
---|
| 184 | ++ item.iItem;
|
---|
| 185 | item.iSubItem = 0;
|
---|
| 186 | item.pszText = strbuf;
|
---|
| 187 | index = ListView_InsertItem(hList, &item);
|
---|
| 188 |
|
---|
| 189 | if(length != 0)
|
---|
| 190 | delete [] strbuf;
|
---|
| 191 |
|
---|
| 192 | wsprintf(buffer, _T("0x%08X -- 0x%08X"), scope->first.GetBase(), scope->first.GetBase() + scope->first.GetLength() - 1);
|
---|
| 193 | ListView_SetItemText(hList, index, 1, buffer);
|
---|
| 194 |
|
---|
| 195 | ++ scope;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | LeaveCriticalSection(&_Module.cs);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 |
|
---|
| 203 | INT CALLBACK MemoryMapDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
| 204 | {
|
---|
| 205 | switch(msg) {
|
---|
| 206 | case WM_INITDIALOG:
|
---|
| 207 | {
|
---|
| 208 | LVCOLUMN col;
|
---|
| 209 |
|
---|
| 210 | HWND hList = GetDlgItem(hDlg, IDC_MAPLIST);
|
---|
| 211 |
|
---|
| 212 | col.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_FMT;
|
---|
| 213 | col.fmt = LVCFMT_LEFT;
|
---|
| 214 | col.pszText = _T("ããã¤ã¹å");
|
---|
| 215 | col.cx = 200;
|
---|
| 216 | ListView_InsertColumn(hList, 0, &col);
|
---|
| 217 |
|
---|
| 218 | col.mask = LVCF_TEXT|LVCF_SUBITEM|LVCF_WIDTH|LVCF_FMT;
|
---|
| 219 | col.pszText = _T("ã¢ãã¬ã¹ç¯å²");
|
---|
| 220 | col.iSubItem = 1;
|
---|
| 221 | col.cx = 230;
|
---|
| 222 | ListView_InsertColumn(hList, 1, &col);
|
---|
| 223 |
|
---|
| 224 | InsertAllDeviceMapList(hList);
|
---|
| 225 |
|
---|
| 226 | break;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | case WM_COMMAND:
|
---|
| 230 | switch(wParam) {
|
---|
| 231 | case IDOK:
|
---|
| 232 | DestroyWindow(hDlg);
|
---|
| 233 | break;
|
---|
| 234 | default:
|
---|
| 235 | FALSE;
|
---|
| 236 | }
|
---|
| 237 | break;
|
---|
| 238 |
|
---|
| 239 | case WM_CLOSE:
|
---|
| 240 | DestroyWindow(hDlg);
|
---|
| 241 | break;
|
---|
| 242 |
|
---|
| 243 | default:
|
---|
| 244 | return FALSE;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | return TRUE;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | void ShowMemoryMapDialog(HWND hParent)
|
---|
| 251 | {
|
---|
| 252 | HWND hDlg = CreateDialog(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_MAPLISTDIALOG), hParent, MemoryMapDialogProc);
|
---|
| 253 | ShowWindow(hDlg, SW_SHOW);
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 |
|
---|
| 257 | //---------------------------------------------------------------------
|
---|
| 258 | // NotifyIcon ã³ã³ããã¹ãã¡ãã¥ã¼
|
---|
| 259 | INT DummyDialogContextMenu(HWND hDlg)
|
---|
| 260 | {
|
---|
| 261 | enum tagMenuID {
|
---|
| 262 | IDM_EXIT = 1,
|
---|
| 263 | IDM_MAPLIST = 2
|
---|
| 264 | };
|
---|
| 265 |
|
---|
| 266 | _TCHAR buffer[128];
|
---|
| 267 |
|
---|
| 268 | HMENU hMenu = CreatePopupMenu();
|
---|
| 269 | if(hMenu == NULL)
|
---|
| 270 | return 0;
|
---|
| 271 |
|
---|
| 272 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, 0, _Module.Kernel != 0 ? _T("ã«ã¼ãã«èµ·åä¸") : _T("ã«ã¼ãã«æªæ¥ç¶"));
|
---|
| 273 | wsprintf(buffer, _T("æ¥ç¶ããã¤ã¹æ° : %d"), _Module.DeviceList.size());
|
---|
| 274 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, 0, buffer);
|
---|
| 275 | wsprintf(buffer, _T("å²ä»æ¸ã¿ç©ºéæ° : %d"), _Module.DeviceMap.size());
|
---|
| 276 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, 0, buffer);
|
---|
| 277 | wsprintf(buffer, _T("æ¥ç¶ã¦ã©ããã£æ° : %d"), _Module.WatcherList.size());
|
---|
| 278 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, 0, buffer);
|
---|
| 279 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_SEPARATOR, 0, NULL);
|
---|
| 280 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, IDM_MAPLIST, _T("ã¡ã¢ãªããã表示"));
|
---|
| 281 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, IDM_EXIT, _T("å¼·å¶çµäº"));
|
---|
| 282 |
|
---|
| 283 | POINT curpos = {0,0};
|
---|
| 284 | GetCursorPos(&curpos);
|
---|
| 285 |
|
---|
| 286 | int cmd = TrackPopupMenu(hMenu, TPM_RIGHTALIGN|TPM_BOTTOMALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, curpos.x, curpos.y, 0, hDlg, NULL);
|
---|
| 287 |
|
---|
| 288 | switch(cmd) {
|
---|
| 289 | case IDM_EXIT:
|
---|
| 290 | PostQuitMessage(0);
|
---|
| 291 | break;
|
---|
| 292 | case IDM_MAPLIST:
|
---|
| 293 | ShowMemoryMapDialog(hDlg);
|
---|
| 294 | break;
|
---|
| 295 | default:
|
---|
| 296 | break;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | return cmd;
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 |
|
---|
| 303 | //---------------------------------------------------------------------
|
---|
| 304 | // NotifyIconç¨ã®ããã¼ãã¤ã¢ãã° ã¡ãã»ã¼ã¸ãã³ãã©
|
---|
| 305 | INT CALLBACK DummyDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
| 306 | {
|
---|
| 307 | switch(msg) {
|
---|
| 308 |
|
---|
| 309 | case WM_NOTIFYICONCALLBACK:
|
---|
| 310 | switch(lParam) {
|
---|
| 311 | case WM_RBUTTONUP:
|
---|
| 312 | DummyDialogContextMenu(hDlg);
|
---|
| 313 | break;
|
---|
| 314 | default:
|
---|
| 315 | return FALSE;
|
---|
| 316 | }
|
---|
| 317 | break;
|
---|
| 318 |
|
---|
| 319 | case WM_INITDIALOG:
|
---|
| 320 | {
|
---|
| 321 | /* ã¿ã¹ã¯ãã¬ã¤ã«ã¢ã¤ã³ã³ãç»é² */
|
---|
| 322 | NOTIFYICONDATA nd;
|
---|
| 323 | HICON hIcon = LoadIcon(ProcessInstance, MAKEINTRESOURCE(IDI_ICON1));
|
---|
| 324 | nd.cbSize = sizeof(nd);
|
---|
| 325 | nd.hWnd = hDlg;
|
---|
| 326 | nd.uID = 100;
|
---|
| 327 | nd.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
|
---|
| 328 | nd.hIcon = hIcon;
|
---|
| 329 | nd.uCallbackMessage = WM_NOTIFYICONCALLBACK;
|
---|
| 330 | ::lstrcpy(nd.szTip, _T("TOPPERS/JSP DeviceManager"));
|
---|
| 331 | Shell_NotifyIcon(NIM_ADD, &nd);
|
---|
| 332 |
|
---|
| 333 | break;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | case WM_DESTROY:
|
---|
| 337 | {
|
---|
| 338 | NOTIFYICONDATA nd;
|
---|
| 339 | nd.cbSize = sizeof(nd);
|
---|
| 340 | nd.hWnd = hDlg;
|
---|
| 341 | nd.uID = 100;
|
---|
| 342 | nd.uFlags = 0;
|
---|
| 343 | Shell_NotifyIcon(NIM_DELETE, &nd);
|
---|
| 344 | break;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | default:
|
---|
| 348 | return FALSE;
|
---|
| 349 | }
|
---|
| 350 |
|
---|
| 351 | return TRUE;
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 |
|
---|
| 355 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 356 | //
|
---|
| 357 | extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
|
---|
| 358 | HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
|
---|
| 359 | {
|
---|
| 360 | lpCmdLine = GetCommandLine(); // ãã®è¡ã¯ _ATL_MIN_CRT ã®ããã«å¿
|
---|
| 361 | è¦ã§ã
|
---|
| 362 |
|
---|
| 363 | #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
|
---|
| 364 | HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
---|
| 365 | #else
|
---|
| 366 | HRESULT hRes = CoInitialize(NULL);
|
---|
| 367 | #endif
|
---|
| 368 | _ASSERTE(SUCCEEDED(hRes));
|
---|
| 369 | _Module.Init(ObjectMap, hInstance, &LIBID_ATLDEVICEMANAGERLib);
|
---|
| 370 | _Module.dwThreadID = GetCurrentThreadId();
|
---|
| 371 | TCHAR szTokens[] = _T("-/");
|
---|
| 372 |
|
---|
| 373 | int nRet = 0;
|
---|
| 374 | BOOL bRun = TRUE;
|
---|
| 375 | LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
|
---|
| 376 | while (lpszToken != NULL)
|
---|
| 377 | {
|
---|
| 378 | if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
|
---|
| 379 | {
|
---|
| 380 | _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, FALSE);
|
---|
| 381 | nRet = _Module.UnregisterServer(TRUE);
|
---|
| 382 | bRun = FALSE;
|
---|
| 383 | break;
|
---|
| 384 | }
|
---|
| 385 | if (lstrcmpi(lpszToken, _T("RegServer"))==0)
|
---|
| 386 | {
|
---|
| 387 | _Module.UpdateRegistryFromResource(IDR_ATLDeviceManager, TRUE);
|
---|
| 388 | nRet = _Module.RegisterServer(TRUE);
|
---|
| 389 | bRun = FALSE;
|
---|
| 390 | break;
|
---|
| 391 | }
|
---|
| 392 | lpszToken = FindOneOf(lpszToken, szTokens);
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | if (bRun)
|
---|
| 396 | {
|
---|
| 397 | HWND dummy_dialog_handle = NULL;
|
---|
| 398 |
|
---|
| 399 | //::AllocConsole();
|
---|
| 400 |
|
---|
| 401 | ProcessInstance = hInstance;
|
---|
| 402 | dummy_dialog_handle = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DUMMYDIALOG), NULL, DummyDialogProc);
|
---|
| 403 | ShowWindow(dummy_dialog_handle, SW_HIDE);
|
---|
| 404 |
|
---|
| 405 | _Module.StartMonitor();
|
---|
| 406 | #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
|
---|
| 407 | hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
|
---|
| 408 | REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
|
---|
| 409 | _ASSERTE(SUCCEEDED(hRes));
|
---|
| 410 | hRes = CoResumeClassObjects();
|
---|
| 411 | #else
|
---|
| 412 | hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
|
---|
| 413 | REGCLS_MULTIPLEUSE);
|
---|
| 414 | #endif
|
---|
| 415 | _ASSERTE(SUCCEEDED(hRes));
|
---|
| 416 |
|
---|
| 417 | MSG msg;
|
---|
| 418 | while (GetMessage(&msg, 0, 0, 0))
|
---|
| 419 | DispatchMessage(&msg);
|
---|
| 420 |
|
---|
| 421 | _Module.RevokeClassObjects();
|
---|
| 422 | Sleep(dwPause); //ã¹ã¬ãããçµäºããã¾ã§å¾
|
---|
| 423 | ã¡ã¾ã
|
---|
| 424 |
|
---|
| 425 | if(dummy_dialog_handle != NULL)
|
---|
| 426 | ::DestroyWindow(dummy_dialog_handle);
|
---|
| 427 |
|
---|
| 428 | ::FreeConsole();
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | _Module.Term();
|
---|
| 432 | CoUninitialize();
|
---|
| 433 | return nRet;
|
---|
| 434 | }
|
---|