diff options
author | Matthew Flatt <mflatt@cs.utah.edu> | 2012-02-16 19:28:56 -0700 |
---|---|---|
committer | Matthew Flatt <mflatt@racket-lang.org> | 2012-02-17 06:36:23 -0700 |
commit | 566e9bb8bfaa83a5abe659368ee48f421c9b12a7 (patch) | |
tree | a4e640166a25025c96970dfb372c1d3cf72afbea /src/mzcom | |
parent | b93eaa19f4e6d9ade3f07167daef701d6d5dc847 (diff) |
make MzCOM /v report errors
Diffstat (limited to 'src/mzcom')
-rw-r--r-- | src/mzcom/mzcom.cxx | 75 |
1 files changed, 65 insertions, 10 deletions
diff --git a/src/mzcom/mzcom.cxx b/src/mzcom/mzcom.cxx index ee2d4b67c1..23592d535e 100644 --- a/src/mzcom/mzcom.cxx +++ b/src/mzcom/mzcom.cxx @@ -95,6 +95,19 @@ LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2) return NULL; } +int IsFlag(LPCTSTR cmd, LPCTSTR flag) +{ + while (*flag) { + if (toupper(*cmd) != toupper(*flag)) + return 0; + cmd++; + flag++; + } + if (!*cmd || (*cmd == ' ')) + return 1; + return 0; +} + #define DLL_RELATIVE_PATH L"lib" #include "../racket/delayed.inc" @@ -124,25 +137,54 @@ extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, _Module.dwThreadID = GetCurrentThreadId(); TCHAR szTokens[] = _T("-/"); - int nRet = 0; + int nRet = 0, verbose = 0; BOOL bRun = TRUE; LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens); while (lpszToken != NULL) { - if (lstrcmpi(lpszToken, _T("UnregServer"))==0) + if (IsFlag(lpszToken, _T("UnregServer"))) { - _Module.UpdateRegistryFromResource(IDR_MZCOM, FALSE); - nRet = _Module.UnregisterServer(TRUE); - bRun = FALSE; - break; + if (!nRet) { + _Module.UpdateRegistryFromResource(IDR_MZCOM, FALSE); + nRet = _Module.UnregisterServer(TRUE); + bRun = FALSE; + } } - if (lstrcmpi(lpszToken, _T("RegServer"))==0) + else if (IsFlag(lpszToken, _T("RegServer"))) { - _Module.UpdateRegistryFromResource(IDR_MZCOM, TRUE); - nRet = _Module.RegisterServer(TRUE); + if (!nRet) { + _Module.UpdateRegistryFromResource(IDR_MZCOM, TRUE); + nRet = _Module.RegisterServer(TRUE); + bRun = FALSE; + } + } + else if (IsFlag(lpszToken, _T("v"))) + { + verbose = 1; + } + else if (IsFlag(lpszToken, _T("?"))) + { + MessageBox(NULL, + _T("/RegServer - register\n" + "/UnregServer - unregister\n" + "/Embedding - ignored\n" + "/v - report failures\n" + "/? - show this help"), + _T("Help"), + MB_OK); bRun = FALSE; - break; } + else if (IsFlag(lpszToken, _T("Embedding"))) + { + /* ??? */ + } + else + { + if (verbose) + MessageBox(NULL, lpszToken, _T("Unknown Flag"), MB_OK); + bRun = FALSE; + break; + } lpszToken = FindOneOf(lpszToken, szTokens); } @@ -173,6 +215,19 @@ extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, Sleep(dwPause); //wait for any threads to finish } + if (verbose && (nRet != 0)) { + wchar_t *res; + FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER + | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + nRet, + 0, + (wchar_t *)&res, + 0, + 0); + MessageBoxW(NULL, res, L"Registration Failed", MB_OK); + } + _Module.Term(); CoUninitialize(); return nRet; |