1*1789df15SXin Li /* 2*1789df15SXin Li * Copyright (C) 2014 The Android Open Source Project 3*1789df15SXin Li * 4*1789df15SXin Li * Licensed under the Apache License, Version 2.0 (the "License"); 5*1789df15SXin Li * you may not use this file except in compliance with the License. 6*1789df15SXin Li * You may obtain a copy of the License at 7*1789df15SXin Li * 8*1789df15SXin Li * http://www.apache.org/licenses/LICENSE-2.0 9*1789df15SXin Li * 10*1789df15SXin Li * Unless required by applicable law or agreed to in writing, software 11*1789df15SXin Li * distributed under the License is distributed on an "AS IS" BASIS, 12*1789df15SXin Li * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*1789df15SXin Li * See the License for the specific language governing permissions and 14*1789df15SXin Li * limitations under the License. 15*1789df15SXin Li */ 16*1789df15SXin Li 17*1789df15SXin Li #pragma once 18*1789df15SXin Li 19*1789df15SXin Li #include <atlpath.h> // ATL CPath 20*1789df15SXin Li 21*1789df15SXin Li // Global flag indicating whether this is running in debug mode (more printfs) 22*1789df15SXin Li extern bool gIsDebug; 23*1789df15SXin Li // Global flag indicating whether this is running in console mode or GUI. 24*1789df15SXin Li // In console mode, errors are written on the console; in GUI they use a MsgBox. 25*1789df15SXin Li extern bool gIsConsole; 26*1789df15SXin Li 27*1789df15SXin Li // Must be called by the application to initialize the app name used in error dialog boxes. 28*1789df15SXin Li // If NULL is used, fetches VERSIONINFO.FileDescription from resources if available. 29*1789df15SXin Li void initUtils(const TCHAR *appName); 30*1789df15SXin Li 31*1789df15SXin Li // Returns the app name set in initUtils 32*1789df15SXin Li CString getAppName(); 33*1789df15SXin Li 34*1789df15SXin Li // Displays a message in an ok+info dialog box. Useful in console mode. 35*1789df15SXin Li void msgBox(const TCHAR* text, ...); 36*1789df15SXin Li 37*1789df15SXin Li // Displays GetLastError prefixed with a description in an error dialog box. Useful in console mode. 38*1789df15SXin Li void displayLastError(const TCHAR *description, ...); 39*1789df15SXin Li 40*1789df15SXin Li // Executes the command line. Does not wait for the program to finish. 41*1789df15SXin Li // The return code is from CreateProcess (0 means failure), not the running app. 42*1789df15SXin Li int execNoWait(const TCHAR *app, const TCHAR *params, const TCHAR *workDir); 43*1789df15SXin Li 44*1789df15SXin Li // Executes command, waits for completion and returns exit code. 45*1789df15SXin Li // As indicated in MSDN for CreateProcess, callers should double-quote the program name 46*1789df15SXin Li // e.g. cmd="\"c:\program files\myapp.exe\" arg1 arg2"; 47*1789df15SXin Li int execWait(const TCHAR *cmd); 48*1789df15SXin Li 49*1789df15SXin Li bool getModuleDir(CPath *outDir); 50*1789df15SXin Li 51*1789df15SXin Li // Disables the FS redirection done by WOW64. 52*1789df15SXin Li // Because this runs as a 32-bit app, Windows automagically remaps some 53*1789df15SXin Li // folder under the hood (e.g. "Programs Files(x86)" is mapped as "Program Files"). 54*1789df15SXin Li // This prevents the app from correctly searching for java.exe in these folders. 55*1789df15SXin Li // The registry is also remapped. 56*1789df15SXin Li PVOID disableWow64FsRedirection(); 57*1789df15SXin Li 58*1789df15SXin Li // Reverts the redirection disabled in disableWow64FsRedirection. 59*1789df15SXin Li void revertWow64FsRedirection(PVOID oldWow64Value); 60