Exemple #1
0
static LANGID 
pGetCmdLineLangID(LPCTSTR lpszCmdLine)
{
	BOOL fSuccess;
	LPTSTR* szArgs = NULL;
	INT nArgs;

	LANGID cmdLangID = 0;

	szArgs = CommandLineToArgv(lpszCmdLine, &nArgs);
	for (INT i = 0; i < nArgs; ++i) {
		if (0 == ::lstrcmpi(_T("/l"),szArgs[i]) ||
			0 == ::lstrcmpi(_T("/lang"), szArgs[i]) ||
			0 == ::lstrcmpi(_T("/language"), szArgs[i]) ||
			0 == ::lstrcmpi(_T("-l"), szArgs[i]) ||
			0 == ::lstrcmpi(_T("-lang"), szArgs[i]) ||
			0 == ::lstrcmpi(_T("-language"), szArgs[i])) 
		{
			if (i + 1 < nArgs) {
				INT iCmdLangID;
				fSuccess = ::StrToIntEx(
					szArgs[i+1], 
					STIF_SUPPORT_HEX, 
					&iCmdLangID);
				if (fSuccess) {
					cmdLangID = (LANGID) iCmdLangID;
				}
				break;
			}
		}
	}
	if (NULL != szArgs) {
		HGLOBAL hNull = ::GlobalFree((HGLOBAL)szArgs);
		ATLASSERT(NULL == hNull);
	}

	return cmdLangID;
}
/*****************************************************************************
lFILEINFO *ParseCommandLine(BOOL *bPipeNecessary)
	bPipeNecessary	: (OUT) true if we were called from the shell extension and
							need to accept pipe input

Return Value:
a filelist to start processing, or NULL if this has been deferred to another instance

Notes:
1) It checks that there are command line parameters
2) If there are, it reads either reads the file names from the command line or signals
   that pipe input from the shell extension neets to be parsed

   If queueing is enabled and there is a previous instance it sends a window message to
   this instance and terminates. The previous instance is then responsible for accepting
   the pipe data/command line
*****************************************************************************/
lFILEINFO *ParseCommandLine(BOOL *bPipeNecessary) {
	INT iNumFiles;
	HWND prevInst;
	TCHAR prevInstTitle[MAX_PATH_EX];

	lFILEINFO *fileList;
	FILEINFO fileinfoTmp = {0};

	fileList = new lFILEINFO;
	fileinfoTmp.parentList = fileList;

	LPTSTR* argv;
	INT argc;
	argv = CommandLineToArgv(GetCommandLine(), &argc);

	*bPipeNecessary = FALSE;
    
	// is there anything to do? (< 2, because 1st element is the path to the executable itself)
	if(argc < 2){
		LocalFree(argv);
		return fileList;
	}
	// use pipe input?
	if( lstrcmpi(argv[1], TEXT("-UsePipeCommunication")) == 0)
	{
		// pipe switches used by the shell extension
		if(argc > 2)
		{
			if(lstrcmpi(argv[2], TEXT("-CreateSFV")) == 0)
			{
				fileList->uiCmdOpts = CMD_SFV;
			}
			else if(lstrcmpi(argv[2], TEXT("-CreateMD5")) == 0)
			{
				fileList->uiCmdOpts = CMD_MD5;
			}
			else if(lstrcmpi(argv[2], TEXT("-CreateSHA1")) == 0)
			{
				fileList->uiCmdOpts = CMD_SHA1;
			}
            else if(lstrcmpi(argv[2], TEXT("-CreateSHA256")) == 0)
			{
				fileList->uiCmdOpts = CMD_SHA256;
			}
            else if(lstrcmpi(argv[2], TEXT("-CreateSHA512")) == 0)
			{
				fileList->uiCmdOpts = CMD_SHA512;
			}
			else if(lstrcmpi(argv[2], TEXT("-PutNAME")) == 0)
			{
				fileList->uiCmdOpts = CMD_NAME;
			}
			else if(lstrcmpi(argv[2], TEXT("-PutNTFS")) == 0)
			{
				fileList->uiCmdOpts = CMD_NTFS;
			}
			else if(lstrcmpi(argv[2], TEXT("-Reparent")) == 0)
			{
				fileList->uiCmdOpts = CMD_REPARENT;
			}
            else if(lstrcmpi(argv[2], TEXT("-HashFilesOnly")) == 0)
			{
				fileList->uiCmdOpts = CMD_ALLHASHES;
			}
            else if(lstrcmpi(argv[2], TEXT("-ForceBSD")) == 0)
			{
				fileList->uiCmdOpts = CMD_FORCE_BSD;
			}
		}
		if(g_program_options.bEnableQueue && GetVersionString(prevInstTitle,MAX_PATH_EX)) {
			prevInst = NULL;
			prevInst = FindWindowEx(NULL,prevInst,TEXT("RapidCrcMainWindow"),prevInstTitle);
			if(prevInst) {
				PostMessage(prevInst,WM_ACCEPT_PIPE,(WPARAM)fileList->uiCmdOpts,NULL);
				delete fileList;
				LocalFree(argv);

				return NULL;
			}
		}

		*bPipeNecessary = TRUE;
	}
	else // not using pipe input => command line parameter are files and folders
	{
		// get number of files
		iNumFiles = argc - 1; // -1 because 1st element is the path to the executable itself

		if(g_program_options.bEnableQueue && GetVersionString(prevInstTitle,MAX_PATH_EX)) {
			prevInst = NULL;
			prevInst = FindWindowEx(NULL,prevInst,TEXT("RapidCrcMainWindow"),prevInstTitle);
			if(prevInst) {
				TCHAR *cmdLine = GetCommandLine();
				COPYDATASTRUCT cdata;
				cdata.dwData = CMDDATA;
				cdata.lpData = cmdLine;
				cdata.cbData = (lstrlen(GetCommandLine()) + 1) * sizeof(TCHAR);

				SendMessage(prevInst,WM_COPYDATA,(WPARAM)0,(LPARAM)&cdata);
				delete fileList;
				LocalFree(argv);
				return NULL;
			}
		}

		for(INT i = 0; i < iNumFiles; ++i){
            fileinfoTmp.szFilename = argv[i+1];
			fileList->fInfos.push_back(fileinfoTmp);
		}
	}

	LocalFree(argv);

	return fileList;
}
Exemple #3
0
int WINAPI _tWinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPTSTR lpCmdLine,
  int nCmdShow
)
{
    int argc;
    TCHAR szMsg[RC_STRING_MAX_SIZE];

    LPTSTR *argv;
    LPTSTR lptCmdLine,lptDllName,lptFuncName,lptMsgBuffer;
    LPSTR lpFuncName,lpaCmdLine;
    LPWSTR lpwCmdLine;
    HMODULE hDll;
    DllWinMainW fnDllWinMainW;
    DllWinMainA fnDllWinMainA;
    HWND hWindow;
    int i;
    size_t nStrLen;

    // Get command-line in argc-argv format
    argv = CommandLineToArgv(GetCommandLine(),&argc);

    // Skip all beginning arguments starting with a slash (/)
    for (i = 1; i < argc; i++)
        if (*argv[i] != _T('/')) break;

    // If no dll was specified, there is nothing to do
    if (i >= argc) {
        if (argv) free(argv);
        return 0;
    }

    lptDllName = argv[i++];

    // The next argument, which specifies the name of the dll function,
    // can either have a comma between it and the dll filename or a space.
    // Using a comma here is the preferred method
    if (i < argc)
        lptFuncName = argv[i++];
    else
        lptFuncName = _T("");

    // If no function name was specified, nothing needs to be done
    if (!*lptFuncName) {
        if (argv) free(argv);
        return 0;
    }

    // The rest of the arguments will be passed to dll function
    if (i < argc)
        lptCmdLine = argv[i];
    else
        lptCmdLine = _T("");

    // Everything is all setup, so load the dll now
    hDll = LoadLibrary(lptDllName);
    if (hDll) {
        nStrLen = _tcslen(lptFuncName);
        // Make a non-unicode version of the function name,
        // since that is all GetProcAddress accepts
        lpFuncName = DuplicateToMultiByte(lptFuncName,nStrLen + 2);

#ifdef UNICODE
        lpFuncName[nStrLen] = 'W';
        lpFuncName[nStrLen+1] = 0;
        // Get address of unicode version of the dll function if it exists
        fnDllWinMainW = (DllWinMainW)GetProcAddress(hDll,lpFuncName);
        fnDllWinMainA = 0;
        if (!fnDllWinMainW) {
            // If no unicode function was found, get the address of the non-unicode function
            lpFuncName[nStrLen] = 'A';
            fnDllWinMainA = (DllWinMainA)GetProcAddress(hDll,lpFuncName);
            if (!fnDllWinMainA) {
                // If first non-unicode function was not found, get the address
                // of the other non-unicode function
                lpFuncName[nStrLen] = 0;
                fnDllWinMainA = (DllWinMainA)GetProcAddress(hDll,lpFuncName);
            }
        }
#else
        // Get address of non-unicode version of the dll function if it exists
        fnDllWinMainA = (DllWinMainA)GetProcAddress(hDll,lpFuncName);
        fnDllWinMainW = 0;
        if (!fnDllWinMainA) {
            // If first non-unicode function was not found, get the address
            // of the other non-unicode function
            lpFuncName[nStrLen] = 'A';
            lpFuncName[nStrLen+1] = 0;
            fnDllWinMainA = (DllWinMainA)GetProcAddress(hDll,lpFuncName);
            if (!fnDllWinMainA) {
                // If non-unicode function was not found, get the address of the unicode function
                lpFuncName[nStrLen] = 'W';
                fnDllWinMainW = (DllWinMainW)GetProcAddress(hDll,lpFuncName);
            }
        }
#endif

        free(lpFuncName);

        if (!RegisterBlankClass(hInstance, hPrevInstance))
        {
            return 0;
        }
        // Create a window so we can pass a window handle to
        // the dll function; this is required
        hWindow = CreateWindowEx(0,rundll32_wclass,rundll32_wtitle,0,CW_USEDEFAULT,0,CW_USEDEFAULT,0,0,0,hInstance,0);

        if (fnDllWinMainW) {
            // Convert the command-line string to unicode and call the dll function
            lpwCmdLine = ConvertToWideChar(lptCmdLine);
            fnDllWinMainW(hWindow,hInstance,lpwCmdLine,nCmdShow);
            FreeConvertedWideChar(lpwCmdLine);
        }
        else if (fnDllWinMainA) {
            // Convert the command-line string to ansi and call the dll function
            lpaCmdLine = ConvertToMultiByte(lptCmdLine);
            fnDllWinMainA(hWindow,hInstance,lpaCmdLine,nCmdShow);
            FreeConvertedMultiByte(lpaCmdLine);
        }
        else {
            // The specified dll function was not found; display an error message
            GetModuleTitle();
            LoadString( GetModuleHandle(NULL), IDS_MissingEntry, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);

            lptMsgBuffer = (LPTSTR)malloc((_tcslen(szMsg) - 4 + _tcslen(lptFuncName) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
            _stprintf(lptMsgBuffer,szMsg,lptFuncName,lptDllName);
            MessageBox(0,lptMsgBuffer,ModuleTitle,MB_ICONERROR);
            free(lptMsgBuffer);
        }

        DestroyWindow(hWindow);
        UnregisterClass(rundll32_wclass,hInstance);

        // The dll function has finished executing, so unload it
        FreeLibrary(hDll);
    }
    else {
        // The dll could not be loaded; display an error message
        GetModuleTitle();
        LoadString( GetModuleHandle(NULL), IDS_DllNotLoaded, (LPTSTR) szMsg,RC_STRING_MAX_SIZE);

        lptMsgBuffer = (LPTSTR)malloc((_tcslen(szMsg) - 2 + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
        _stprintf(lptMsgBuffer,szMsg,lptDllName);

        MessageBox(0,lptMsgBuffer,ModuleTitle,MB_ICONERROR);
        free(lptMsgBuffer);
    }

    if (argv) free(argv);
    return 0; /* rundll32 always returns 0! */
}
Exemple #4
0
int WINAPI _tWinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPTSTR lpCmdLine,
  int nCmdShow
)
{
	int argc;
	LPTSTR *argv;
	LPTSTR lptDllName,lptDllCmdLine,lptMsgBuffer;
	LPCTSTR lptFuncName;
	LPCSTR lpFuncName;
	LPWSTR lpwDllCmdLine;
	BOOL bUnregister,bSilent,bConsole,bInstall,bNoRegister;
	UINT nDllCount;
	HMODULE hDll;
	DLLREGISTER fnDllRegister;
	DLLINSTALL fnDllInstall;
	HRESULT hResult;
	DWORD dwErr;
	int nRetValue,i;

	// Get Langues msg
	LoadString( GetModuleHandle(NULL), IDS_UsageMessage, (LPTSTR) UsageMessage,RC_STRING_MAX_SIZE);
	LoadString( GetModuleHandle(NULL), IDS_NoDllSpecified, (LPTSTR) NoDllSpecified,RC_STRING_MAX_SIZE);
	LoadString( GetModuleHandle(NULL), IDS_InvalidFlag, (LPTSTR) InvalidFlag,RC_STRING_MAX_SIZE);
	LoadString( GetModuleHandle(NULL), IDS_SwitchN_NoI, (LPTSTR) SwitchN_NoI,RC_STRING_MAX_SIZE);

	LoadString( GetModuleHandle(NULL), IDS_DllNotLoaded, (LPTSTR)   DllNotLoaded,RC_STRING_MAX_SIZE);
	LoadString( GetModuleHandle(NULL), IDS_MissingEntry, (LPTSTR)   MissingEntry,RC_STRING_MAX_SIZE);
	LoadString( GetModuleHandle(NULL), IDS_FailureMessage, (LPTSTR) FailureMessage,RC_STRING_MAX_SIZE);
	LoadString( GetModuleHandle(NULL), IDS_SuccessMessage, (LPTSTR) SuccessMessage,RC_STRING_MAX_SIZE);

	// Get command-line in argc-argv format
	argv = CommandLineToArgv(GetCommandLine(),&argc);

	// Initialize variables
	lptFuncName = 0;
	lptDllCmdLine = 0;
	nDllCount = 0;
	bUnregister = FALSE;
	bSilent = FALSE;
	bConsole = FALSE;
	bInstall = FALSE;
	bNoRegister = FALSE;

	// Find all arguments starting with a slash (/)
	for (i = 1; i < argc; i++) {
		if (*argv[i] == _T('/')) {
			switch (argv[i][1]) {
			case _T('u'):
			case _T('U'):
				bUnregister = TRUE;
				break;
			case _T('s'):
			case _T('S'):
				bSilent = TRUE;
				break;
			case _T('c'):
			case _T('C'):
				bConsole = TRUE;
				break;
			case _T('i'):
			case _T('I'):
				bInstall = TRUE;
				lptDllCmdLine = argv[i];
				while (*lptDllCmdLine != 0 && *lptDllCmdLine != _T(':'))
					lptDllCmdLine++;
				if (*lptDllCmdLine == _T(':'))
					lptDllCmdLine++;
				break;
			case _T('n'):
			case _T('N'):
				bNoRegister = TRUE;
				break;
			default:
				if (!lptFuncName)
					lptFuncName = argv[i];
			}
		}
		else {
			nDllCount++;
		}
	}

	// An unrecognized flag was used, display a message and show available options

	if (lptFuncName) {
		lptMsgBuffer = (LPTSTR)malloc((_tcslen(UsageMessage) - 2 + _tcslen(InvalidFlag) - 2 + _tcslen(lptFuncName) + 1) * sizeof(TCHAR));
		_stprintf(lptMsgBuffer + (_tcslen(UsageMessage) - 2),InvalidFlag,lptFuncName);
		_stprintf(lptMsgBuffer,UsageMessage,lptMsgBuffer + (_tcslen(UsageMessage) - 2));
		DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
		free(lptMsgBuffer);
		GlobalFree(argv);
		return EXITCODE_PARAMERROR;
	}

	// /n was used without /i, display a message and show available options
	if (bNoRegister && (!bInstall)) {
		lptMsgBuffer = (LPTSTR)malloc((_tcslen(UsageMessage) - 2 + _tcslen(SwitchN_NoI) + 1) * sizeof(TCHAR));
		_stprintf(lptMsgBuffer,UsageMessage,SwitchN_NoI);
		DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
		free(lptMsgBuffer);
		GlobalFree(argv);
		return EXITCODE_PARAMERROR;
	}

	// No dll was specified, display a message and show available options
	if (nDllCount == 0) {
		lptMsgBuffer = (LPTSTR)malloc((_tcslen(UsageMessage) - 2 + _tcslen(NoDllSpecified) + 1) * sizeof(TCHAR));
		_stprintf(lptMsgBuffer,UsageMessage,NoDllSpecified);
		DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
		free(lptMsgBuffer);
		GlobalFree(argv);
		return EXITCODE_PARAMERROR;
	}

	nRetValue = EXITCODE_SUCCESS;
	if (!bUnregister) {
		lpFuncName = szDllRegister;
		lptFuncName = tszDllRegister;
	}
	else {
		lpFuncName = szDllUnregister;
		lptFuncName = tszDllUnregister;
	}

	if (lptDllCmdLine)
		lpwDllCmdLine = ConvertToWideChar(lptDllCmdLine);
	else
		lpwDllCmdLine = 0;

	// Initialize OLE32 before attempting to register the
	// dll.  Some dll's require this to register properly
	OleInitialize(0);

	// (Un)register every dll whose filename was passed in the command-line string
	for (i = 1; i < argc && nRetValue == EXITCODE_SUCCESS; i++) {
		// Arguments that do not start with a slash (/) are filenames
		if (*argv[i] != _T('/')) {
			lptDllName = argv[i];

			// Everything is all setup, so load the dll now
			hDll = LoadLibraryEx(lptDllName,0,LOAD_WITH_ALTERED_SEARCH_PATH);
			if (hDll) {
				if (!bNoRegister) {
					// Get the address of DllRegisterServer or DllUnregisterServer
					fnDllRegister = (DLLREGISTER)GetProcAddress(hDll,lpFuncName);
					if (fnDllRegister) {
						// If the function exists, call it
						hResult = fnDllRegister();
						if (hResult == S_OK) {
							// (Un)register succeeded, display a message
							lptMsgBuffer = (LPTSTR)malloc((_tcslen(SuccessMessage) - 4 + _tcslen(lptFuncName) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
							_stprintf(lptMsgBuffer,SuccessMessage,lptFuncName,lptDllName);
							DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONINFORMATION);
						}
						else {
							// (Un)register failed, display a message
							lptMsgBuffer = (LPTSTR)malloc((_tcslen(FailureMessage) + _tcslen(lptFuncName) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
							_stprintf(lptMsgBuffer,FailureMessage,lptFuncName,lptDllName,hResult);
							DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
						}
						free(lptMsgBuffer);
						if (hResult != S_OK)
							nRetValue = EXITCODE_FAILURE;
					}
					else {
						FreeLibrary(hDll);
						// Dll(Un)register was not found, display an error message
						lptMsgBuffer = (LPTSTR)malloc((_tcslen(MissingEntry) - 8 + _tcslen(lptFuncName) * 2 + _tcslen(lptDllName) * 2 + 1) * sizeof(TCHAR));
						_stprintf(lptMsgBuffer,MissingEntry,lptDllName,lptFuncName,lptFuncName,lptDllName);
						DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
						free(lptMsgBuffer);
						nRetValue = EXITCODE_NOENTRY;
					}
				}

				if (bInstall && nRetValue == EXITCODE_SUCCESS) {
					// Get the address of DllInstall
					fnDllInstall = (DLLINSTALL)GetProcAddress(hDll,szDllInstall);
					if (fnDllInstall) {
						// If the function exists, call it
						if (!bUnregister)
							hResult = fnDllInstall(1,lpwDllCmdLine);
						else
							hResult = fnDllInstall(0,lpwDllCmdLine);
						if (hResult == S_OK) {
							// (Un)install succeeded, display a message
							lptMsgBuffer = (LPTSTR)malloc((_tcslen(SuccessMessage) - 4 + _tcslen(tszDllInstall) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
							_stprintf(lptMsgBuffer,SuccessMessage,tszDllInstall,lptDllName);
							DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONINFORMATION);
						}
						else {
							// (Un)install failed, display a message
							lptMsgBuffer = (LPTSTR)malloc((_tcslen(FailureMessage) + _tcslen(tszDllInstall) + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
							_stprintf(lptMsgBuffer,FailureMessage,tszDllInstall,lptDllName,hResult);
							DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
						}
						free(lptMsgBuffer);
						if (hResult != S_OK)
							nRetValue = EXITCODE_FAILURE;
					}
					else {
						FreeLibrary(hDll);
						// DllInstall was not found, display an error message
						lptMsgBuffer = (LPTSTR)malloc((_tcslen(MissingEntry) - 8 + _tcslen(tszDllInstall) * 2 + _tcslen(lptDllName) * 2 + 1) * sizeof(TCHAR));
						_stprintf(lptMsgBuffer,MissingEntry,lptDllName,tszDllInstall,tszDllInstall,lptDllName);
						DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
						free(lptMsgBuffer);
						nRetValue = EXITCODE_NOENTRY;
					}
				}

				// The dll function has finished executing, so unload it
				FreeLibrary(hDll);
			}
			else {
				// The dll could not be loaded; display an error message
				dwErr = GetLastError();
				lptMsgBuffer = (LPTSTR)malloc((_tcslen(DllNotLoaded) + 2 + _tcslen(lptDllName) + 1) * sizeof(TCHAR));
				_stprintf(lptMsgBuffer,DllNotLoaded,lptDllName,dwErr);
				DisplayMessage(bConsole,bSilent,lptMsgBuffer,ModuleTitle,MB_ICONEXCLAMATION);
				free(lptMsgBuffer);
				nRetValue = EXITCODE_LOADERROR;
			}
		}
	}

	if (lpwDllCmdLine)
		FreeConvertedWideChar(lpwDllCmdLine);
	GlobalFree(argv);
	OleUninitialize();
	return nRetValue;
}
int
WINAPI
WinMain(
    HINSTANCE   hInstance,
    HINSTANCE   hPrevInstance,
    PSTR        szCmdLine,
    int         iCmdShow)
/*++

Routine Description:

    Entry point for the application

Returns:

    An exit code of application - we always return 0

--*/
{
    int funcResult = 0;

    // Common controls must be initialized
    InitCommonControls();

    ghInstance = hInstance;

    LPTSTR cmdLine = GetCommandLine();
    int argC = 0;
    LPTSTR *argV = CommandLineToArgv(cmdLine, &argC);

    if (argC <= 1)
    {
        HWND hwnd = GetDesktopWindow();
        int err = GetLastError();

        DialogBoxParam(
                ghInstance,
                MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
                GetDesktopWindow(),
                (DLGPROC)AboutDlgProc,
                (LPARAM)NULL);

        err = GetLastError();
        err = err + 1;
    }
    else
    {
        DWORD pid       = 0;
        HANDLE hEvent   = NULL;

        if (cdProcessArguments(argC, argV, pid, hEvent))
        {
            PROC_DBG_DATA procDbgData;

            procDbgData.processId   = pid;
            procDbgData.eventHandle = hEvent;

            INT_PTR dlgResult = DialogBoxParam(
                                ghInstance,
                                MAKEINTRESOURCE(IDD_DIALOG_HANDLE_CRASH),
                                GetDesktopWindow(),
                                (DLGPROC)HandleCrashDlgProc,
                                (LPARAM)&procDbgData);

            if (dlgResult == IDC_BTN_RECOVER)
            {
                CRecoveryHandler recoveryHandler(
                                        procDbgData.processId,
                                        procDbgData.eventHandle);

                DialogBoxParam(
                            ghInstance,
                            MAKEINTRESOURCE(IDD_DIALOG_RECOVER_STATUS),
                            GetDesktopWindow(),
                            (DLGPROC)RecoveryStatusDlgProc,
                            (LPARAM)&recoveryHandler);

            }
            else if(dlgResult == IDC_BTN_TERMINATE)
            {
                HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

                if (hProcess)
                {
                    TerminateProcess(hProcess, -1);
                    CloseHandle(hProcess);
                }

                if (hEvent)
                {
                    SetEvent(hEvent);
                    hEvent = NULL;
                }
            }
#if 0
            else if (dlgResult = IDC_BTN_ABOUT)
            {
                DialogBoxParam(
                    ghInstance,
                    MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
                    GetDesktopWindow(),
                    (DLGPROC)AboutDlgProc,
                    (LPARAM)NULL);
            }
#endif
        }
    }

    goto funcExit;

funcExit:
    return funcResult;
}
BOOL CCommandLineOption::Parse(CString strCommandLine)
{
	TCHAR** argv;
	int argc;
	int i;

	m_strErrorMsg = TEXT("");
	m_strDisk1Path = TEXT("");
	m_strDisk2Path = TEXT("");
	m_strHardDiskPath = TEXT("");
	m_strStatePath = TEXT("");
	m_bSaveOnExit = FALSE;
	m_bReboot = FALSE;

	argv = CommandLineToArgv(strCommandLine, &argc);

	for (i = 1; i < argc; i++)
	{
		if (i < argc - 1)
		{
			if (_tcscmp(argv[i], TEXT("-d1")) == 0)
			{
				m_strDisk1Path = argv[i + 1];
				i++;
				continue;
			}
			else if (_tcscmp(argv[i], TEXT("-d2")) == 0)
			{
				m_strDisk2Path = argv[i + 1];
				i++;
				continue;
			}
			else if (_tcscmp(argv[i], TEXT("-h")) == 0)
			{
				m_strHardDiskPath = argv[i + 1];
				i++;
				continue;
			}
			else if (_tcscmp(argv[i], TEXT("-s")) == 0)
			{
				m_strStatePath = argv[i + 1];
				i++;
				continue;
			}
		}
		if (_tcscmp(argv[i], TEXT("-w")) == 0)
		{
			m_bSaveOnExit = TRUE;
			continue;
		}
		else if (_tcscmp(argv[i], TEXT("-r")) == 0)
		{
			m_bReboot = TRUE;
			continue;
		}
		break;
	}
	LocalFree(argv);
	if (i < argc)
	{
		m_strErrorMsg.Format(TEXT("Invalid argument: %s"), argv[i]);
		return FALSE;
	}
	return TRUE;
}
Exemple #7
0
BOOL
InitializeOptions
(
    IN      LPSTR   lpCmdLine
)
{
    BOOL Success1 = FALSE;
    BOOL Success2 = FALSE;

    DWORD ArgC = 0;

    LPTSTR * ArgV = CommandLineToArgv(lpCmdLine, &ArgC);

    if (ArgV)
    {
        for (DWORD i=0; i<ArgC; i++)
        {
            if (_stricmp(ArgV[i], "/s")==0)
            {
                OptionSilent = TRUE;
            }
            else if (_stricmp(ArgV[i],"/silent")==0)
            {
                OptionSilent = TRUE;
            }
            else if (_stricmp(ArgV[i],"/path")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    strcpy(InfPath, ArgV[i+1]);

                    Success1 = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/path:relative")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    GetCurrentDirectory(MAX_PATH, InfPath);
                    strcat(InfPath, "\\");
                    strcat(InfPath, ArgV[i+1]);

                    Success1 = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/ddinstall")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    strcpy(DDInstallSection, ArgV[i+1]);

                    Success2 = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/os")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    strcpy(ExpectedOsVersion, ArgV[i+1]);

                    OptionOsVersionCheck = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/buildnumber")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    ExpectedOsBuildNumber = atoi(ArgV[i+1]);

                    OptionOsBuildNumberCheck = TRUE;
                    i++;
                }
            }
            else if (_stricmp(ArgV[i],"/sp")==0)
            {
                if (((i+1)<ArgC) && (ArgV[i+1]))
                {
                    ExpectedOsServicePack = atoi(ArgV[i+1]);

                    OptionOsServicePackCheck = TRUE;
                    i++;
                }
            }
        }

        GlobalFree(HGLOBAL(ArgV));
    }

    return (Success1 && Success2);
}