您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ ExpandEnvironmentStringsW函数代码示例

51自学网 2021-06-01 20:40:02
  C++
这篇教程C++ ExpandEnvironmentStringsW函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中ExpandEnvironmentStringsW函数的典型用法代码示例。如果您正苦于以下问题:C++ ExpandEnvironmentStringsW函数的具体用法?C++ ExpandEnvironmentStringsW怎么用?C++ ExpandEnvironmentStringsW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了ExpandEnvironmentStringsW函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: win32_find_system

static int win32_find_system(char *system_config_path){	const wchar_t *query = L"%PROGRAMFILES%//Git//etc//gitconfig";	wchar_t *apphome_utf16;	char *apphome_utf8;	DWORD size, ret;	size = ExpandEnvironmentStringsW(query, NULL, 0);	/* The function gave us the full size of the buffer in chars, including NUL */	apphome_utf16 = git__malloc(size * sizeof(wchar_t));	if (apphome_utf16 == NULL)		return GIT_ENOMEM;	ret = ExpandEnvironmentStringsW(query, apphome_utf16, size);	if (ret != size)		return git__throw(GIT_ERROR, "Failed to expand environment strings");	if (_waccess(apphome_utf16, F_OK) < 0) {		free(apphome_utf16);		return GIT_ENOTFOUND;	}	apphome_utf8 = conv_utf16_to_utf8(apphome_utf16);	free(apphome_utf16);	if (strlen(apphome_utf8) >= GIT_PATH_MAX) {		free(apphome_utf8);		return git__throw(GIT_ESHORTBUFFER, "Path is too long");	}	strcpy(system_config_path, apphome_utf8);	free(apphome_utf8);	return GIT_SUCCESS;}
开发者ID:businessintelligence,项目名称:libgit2,代码行数:34,


示例2: apxExpandStrW

LPWSTRapxExpandStrW(APXHANDLE hPool, LPCWSTR szString){    LPCWSTR p = szString;    while (*p) {        if (*p == L'%') {            p = szString;            break;        }        ++p;    }    if (p != szString)        return apxPoolStrdupW(hPool, szString);    else {        DWORD l = ExpandEnvironmentStringsW(szString, NULL, 0);        if (l) {            LPWSTR rv = apxPoolAlloc(hPool, l * sizeof(WCHAR));            l = ExpandEnvironmentStringsW(szString, rv, l);            if (l)                return rv;            else {                apxFree(rv);                return NULL;            }        }        else            return NULL;    }}
开发者ID:VertiPub,项目名称:jsvc,代码行数:29,


示例3: g_getenv

const gchar *g_getenv (const gchar *variable){  GQuark quark;  gchar *value;  wchar_t dummy[2], *wname, *wvalue;  int len;  g_return_val_if_fail (variable != NULL, NULL);  g_return_val_if_fail (g_utf8_validate (variable, -1, NULL), NULL);  /* On Windows NT, it is relatively typical that environment   * variables contain references to other environment variables. If   * so, use ExpandEnvironmentStrings(). (In an ideal world, such   * environment variables would be stored in the Registry as   * REG_EXPAND_SZ type values, and would then get automatically   * expanded before a program sees them. But there is broken software   * that stores environment variables as REG_SZ values even if they   * contain references to other environment variables.)   */  wname = g_utf8_to_utf16 (variable, -1, NULL, NULL, NULL);  len = GetEnvironmentVariableW (wname, dummy, 2);  if (len == 0)    {      g_free (wname);      return NULL;    }  else if (len == 1)    len = 2;  wvalue = g_new (wchar_t, len);  if (GetEnvironmentVariableW (wname, wvalue, len) != len - 1)    {      g_free (wname);      g_free (wvalue);      return NULL;    }  if (wcschr (wvalue, L'%') != NULL)    {      wchar_t *tem = wvalue;      len = ExpandEnvironmentStringsW (wvalue, dummy, 2);      if (len > 0)        {          wvalue = g_new (wchar_t, len);          if (ExpandEnvironmentStringsW (tem, wvalue, len) != len)            {              g_free (wvalue);              wvalue = tem;            }          else            g_free (tem);        }
开发者ID:01org,项目名称:android-bluez-glib,代码行数:60,


示例4: ExpandEnvironmentStringsW

/* Returns a string that corresponds to <data> with all existing * environment variables replaced by their values and with * %* and %N replaced by the respective command line arguments, taken from <argv>. * The resulting string is allocated by expand_vars() and must be freed with free(). */wchar_t *expand_vars (wchar_t *data, wchar_t *argv[]){  DWORD res = 0;  DWORD extra_len = 0;  size_t newlen = 0;  wchar_t *result;  wchar_t *arg_result;  int i = 0, j = 0;  BOOL prevrep = FALSE;  size_t len = 0;  int argc;  res = ExpandEnvironmentStringsW (data, NULL, 0);  if (res == 0)    return NULL;  result = (wchar_t *) malloc (sizeof(wchar_t) * res);  if (result == NULL)    return NULL;  res = ExpandEnvironmentStringsW (data, result, res);  if (res == 0)  {    free (result);      return NULL;  }  argc = 0;  for (arg_result = argv[0]; arg_result != NULL; arg_result = argv[argc])    argc += 1;  scan_vars (result, res, &newlen, NULL, argc, argv);  arg_result = (wchar_t *) malloc (sizeof (wchar_t) * (newlen + 1));  scan_vars (result, res, NULL, arg_result, argc, argv);  free (result);  return arg_result;}
开发者ID:LRN,项目名称:mimerun,代码行数:39,


示例5: BuildCommandLine

static size_tBuildCommandLine(LPWSTR lpszDest, LPCWSTR lpszCmdLine, LPCWSTR lpszParam, size_t bufSize){    size_t numOfChars = 0; // The null character is counted in ExpandEnvironmentStrings(...).    // TODO: Take into account the "plus one" for numOfChars for ANSI version (see MSDN for more details).    if (lpszCmdLine && *lpszCmdLine)    {        numOfChars += ExpandEnvironmentStringsW(lpszCmdLine, NULL, 0);        if (lpszDest)            ExpandEnvironmentStringsW(lpszCmdLine, lpszDest, (DWORD)bufSize); // TODO: size_t to DWORD conversion !        if (lpszParam && *lpszParam)        {            ++numOfChars;            if (lpszDest)                wcscat(lpszDest, L" ");        }    }    if (lpszParam && *lpszParam)    {        numOfChars += wcslen(lpszParam);        if (lpszDest)            wcscat(lpszDest, lpszParam);    }    return numOfChars;}
开发者ID:Moteesh,项目名称:reactos,代码行数:29,


示例6: ExpandEnv

/* Allocate and initialize a WSTR containing the expanded string */static LPWSTR ExpandEnv(LPWSTR string){    DWORD size;    LPWSTR expanded_string;    WINE_TRACE("/n");    size = 0;    size = ExpandEnvironmentStringsW(string, NULL, size);    if (size == 0)    {        WINE_ERR("cannot expand env vars in %s: %u/n",                wine_dbgstr_w(string), GetLastError());        return NULL;    }    expanded_string = HeapAlloc(GetProcessHeap(), 0,            (size + 1) * sizeof(WCHAR));    if (ExpandEnvironmentStringsW(string, expanded_string, size) == 0)    {        WINE_ERR("cannot expand env vars in %s: %u/n",                wine_dbgstr_w(string), GetLastError());        HeapFree(GetProcessHeap(), 0, expanded_string);        return NULL;    }    return expanded_string;}
开发者ID:DeltaYang,项目名称:wine,代码行数:27,


示例7: GetTempCachePath

/***     bChoose = true    %temp%*     bChoose = false   %appdata%*/tstring GetTempCachePath(HINSTANCE hInstance, bool bChoose = false){	LPTSTR lpszTempPath = new TCHAR[MAX_PATH + 1];	int nLength = 0;	if( bChoose )		nLength = GetTempPath(MAX_PATH, lpszTempPath);	else		nLength = ExpandEnvironmentStringsW(L"%appdata%", lpszTempPath, MAX_PATH);	if (nLength > MAX_PATH)	{		delete[] lpszTempPath;		lpszTempPath = new TCHAR[nLength + 1];		if( bChoose )			GetTempPath(nLength, lpszTempPath);		else			ExpandEnvironmentStringsW(L"%appdata%", lpszTempPath, nLength);	}	lpszTempPath[nLength] = '/0';	tstring path = lpszTempPath;		delete[] lpszTempPath;	if (path[path.size() - 1] != '//')		path += _T("//");	path += _T("BankUpdate");	CreateDirectory(path.c_str(), NULL);	return path;}
开发者ID:Williamzuckerberg,项目名称:chtmoneyhub,代码行数:37,


示例8: ExpandEnvironmentStringsW

HRESULT CQueryAssociations::GetExecutable(LPCWSTR pszExtra, LPWSTR path, DWORD pathlen, DWORD *len){    WCHAR *pszCommand;    WCHAR *pszStart;    WCHAR *pszEnd;    HRESULT hr = this->GetCommand(pszExtra, &pszCommand);    if (FAILED(hr))    {        return hr;    }        DWORD expLen = ExpandEnvironmentStringsW(pszCommand, NULL, 0);    if (expLen > 0)    {        expLen++;        WCHAR *buf = static_cast<WCHAR *>(HeapAlloc(GetProcessHeap(), 0, expLen * sizeof(WCHAR)));        ExpandEnvironmentStringsW(pszCommand, buf, expLen);        HeapFree(GetProcessHeap(), 0, pszCommand);        pszCommand = buf;    }        /* cleanup pszCommand */    if (pszCommand[0] == '"')    {        pszStart = pszCommand + 1;        pszEnd = strchrW(pszStart, '"');        if (pszEnd)        {            *pszEnd = 0;        }        *len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);    }    else    {        pszStart = pszCommand;        for (pszEnd = pszStart; (pszEnd = strchrW(pszEnd, ' ')); pszEnd++)        {            WCHAR c = *pszEnd;            *pszEnd = 0;            if ((*len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL)))            {                break;            }            *pszEnd = c;        }        if (!pszEnd)        {            *len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);        }    }    HeapFree(GetProcessHeap(), 0, pszCommand);    if (!*len)    {        return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);    }    return S_OK;}
开发者ID:Moteesh,项目名称:reactos,代码行数:59,


示例9: GetProfilesDirectoryW

BOOL WINAPI GetProfilesDirectoryW( LPWSTR lpProfilesDir, LPDWORD lpcchSize ){    static const WCHAR ProfilesDirectory[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};    LONG l;    HKEY key;    BOOL ret = FALSE;    DWORD len = 0, expanded_len;    LPWSTR unexpanded_profiles_dir = NULL;    TRACE("%p %p/n", lpProfilesDir, lpcchSize );    if (!lpcchSize)    {        SetLastError(ERROR_INVALID_PARAMETER);        return FALSE;    }    l = RegOpenKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, KEY_READ, &key);    if (l)    {        SetLastError(l);        return FALSE;    }    l = RegQueryValueExW(key, ProfilesDirectory, NULL, NULL, NULL, &len);    if (l)    {        SetLastError(l);        goto end;    }    unexpanded_profiles_dir = HeapAlloc(GetProcessHeap(), 0, len);    if (!unexpanded_profiles_dir)    {        SetLastError(ERROR_OUTOFMEMORY);        goto end;    }    l = RegQueryValueExW(key, ProfilesDirectory, NULL, NULL,                             (BYTE *)unexpanded_profiles_dir, &len);    if (l)    {        SetLastError(l);        goto end;    }    expanded_len = ExpandEnvironmentStringsW(unexpanded_profiles_dir, NULL, 0);    /* The returned length doesn't include the NULL terminator. */    if (*lpcchSize < expanded_len - 1 || !lpProfilesDir)    {        *lpcchSize = expanded_len - 1;        SetLastError(ERROR_INSUFFICIENT_BUFFER);        goto end;    }    *lpcchSize = expanded_len - 1;    /* The return value is also the expected length. */    ret = ExpandEnvironmentStringsW(unexpanded_profiles_dir, lpProfilesDir,                                    expanded_len) - 1;end:    HeapFree(GetProcessHeap(), 0, unexpanded_profiles_dir);    RegCloseKey(key);    return ret;}
开发者ID:bpon,项目名称:wine,代码行数:59,


示例10: service_start_process

static DWORD service_start_process(struct service_entry *service_entry, HANDLE *process){    PROCESS_INFORMATION pi;    STARTUPINFOW si;    LPWSTR path = NULL;    DWORD size;    BOOL r;    service_lock_exclusive(service_entry);    if (service_entry->config.dwServiceType == SERVICE_KERNEL_DRIVER)    {        static const WCHAR winedeviceW[] = {'//','w','i','n','e','d','e','v','i','c','e','.','e','x','e',' ',0};        DWORD len = GetSystemDirectoryW( NULL, 0 ) + sizeof(winedeviceW)/sizeof(WCHAR) + strlenW(service_entry->name);        if (!(path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))            return ERROR_NOT_ENOUGH_SERVER_MEMORY;        GetSystemDirectoryW( path, len );        lstrcatW( path, winedeviceW );        lstrcatW( path, service_entry->name );    }    else    {        size = ExpandEnvironmentStringsW(service_entry->config.lpBinaryPathName,NULL,0);        path = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));        if (!path)            return ERROR_NOT_ENOUGH_SERVER_MEMORY;        ExpandEnvironmentStringsW(service_entry->config.lpBinaryPathName,path,size);    }    ZeroMemory(&si, sizeof(STARTUPINFOW));    si.cb = sizeof(STARTUPINFOW);    if (!(service_entry->config.dwServiceType & SERVICE_INTERACTIVE_PROCESS))    {        static WCHAR desktopW[] = {'_','_','w','i','n','e','s','e','r','v','i','c','e','_','w','i','n','s','t','a','t','i','o','n','//','D','e','f','a','u','l','t',0};        si.lpDesktop = desktopW;    }    service_entry->status.dwCurrentState = SERVICE_START_PENDING;    service_unlock(service_entry);    r = CreateProcessW(NULL, path, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);    HeapFree(GetProcessHeap(),0,path);    if (!r)    {        service_lock_exclusive(service_entry);        service_entry->status.dwCurrentState = SERVICE_STOPPED;        service_unlock(service_entry);        return GetLastError();    }    service_entry->status.dwProcessId = pi.dwProcessId;    *process = pi.hProcess;    CloseHandle( pi.hThread );    return ERROR_SUCCESS;}
开发者ID:bilboed,项目名称:wine,代码行数:58,


示例11: expand_env_vars

wstring expand_env_vars(const wstring& str) {  Buffer<wchar_t> buf(MAX_PATH);  unsigned size = ExpandEnvironmentStringsW(str.c_str(), buf.data(), static_cast<DWORD>(buf.size()));  if (size > buf.size()) {    buf.resize(size);    size = ExpandEnvironmentStringsW(str.c_str(), buf.data(), static_cast<DWORD>(buf.size()));  }  CHECK_SYS(size);  return wstring(buf.data(), size - 1);}
开发者ID:landswellsong,项目名称:FAR,代码行数:10,


示例12: ExpandEnvironmentStringsW

void ConsoleTools::setCatalogPath(const String &str) {  delete catalogPath;#if defined _WIN32   // replace the environment variables to their values  size_t i=ExpandEnvironmentStringsW(str.getWChars(),NULL,0);  wchar_t *temp = new wchar_t[i];  ExpandEnvironmentStringsW(str.getWChars(),temp,static_cast<DWORD>(i));  catalogPath = new SString(temp);  delete[] temp;#else  catalogPath = new SString(str);#endif}
开发者ID:CS-svnmirror,项目名称:colorer,代码行数:13,


示例13: ACTION_ConvertRegValue

static void ACTION_ConvertRegValue(DWORD regType, const BYTE *value, DWORD sz, LPWSTR *appValue){    static const WCHAR dwordFmt[] = { '#','%','d','/0' };    static const WCHAR binPre[] = { '#','x','/0' };    static const WCHAR binFmt[] = { '%','0','2','X','/0' };    LPWSTR ptr;    DWORD i;    switch (regType)    {        case REG_SZ:            if (*(LPCWSTR)value == '#')            {                /* escape leading pound with another */                *appValue = msi_alloc(sz + sizeof(WCHAR));                (*appValue)[0] = '#';                strcpyW(*appValue + 1, (LPCWSTR)value);            }            else            {                *appValue = msi_alloc(sz);                strcpyW(*appValue, (LPCWSTR)value);            }            break;        case REG_DWORD:            /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign             * char if needed             */            *appValue = msi_alloc(10 * sizeof(WCHAR));            sprintfW(*appValue, dwordFmt, *(const DWORD *)value);            break;        case REG_EXPAND_SZ:            sz = ExpandEnvironmentStringsW((LPCWSTR)value, NULL, 0);            *appValue = msi_alloc(sz * sizeof(WCHAR));            ExpandEnvironmentStringsW((LPCWSTR)value, *appValue, sz);            break;        case REG_BINARY:            /* #x<nibbles>/0 */            *appValue = msi_alloc((sz * 2 + 3) * sizeof(WCHAR));            lstrcpyW(*appValue, binPre);            ptr = *appValue + lstrlenW(binPre);            for (i = 0; i < sz; i++, ptr += 2)                sprintfW(ptr, binFmt, value[i]);            break;        default:            WARN("unimplemented for values of type %d/n", regType);            *appValue = NULL;    }}
开发者ID:pstrealer,项目名称:wine,代码行数:50,


示例14: query_reg_path

/* At the end of the day this is a subset of what SHRegGetPath() does - copied * here to avoid linking against shlwapi. */static DWORD query_reg_path (HKEY hKey, LPCWSTR lpszValue,                             LPVOID pvData){  DWORD dwRet, dwType, dwUnExpDataLen = MAX_PATH, dwExpDataLen;  TRACE("(hkey=%p,%s,%p)/n", hKey, debugstr_w(lpszValue),        pvData);  dwRet = RegQueryValueExW(hKey, lpszValue, 0, &dwType, pvData, &dwUnExpDataLen);  if (dwRet!=ERROR_SUCCESS && dwRet!=ERROR_MORE_DATA)      return dwRet;  if (dwType == REG_EXPAND_SZ)  {    DWORD nBytesToAlloc;    /* Expand type REG_EXPAND_SZ into REG_SZ */    LPWSTR szData;    /* If the caller didn't supply a buffer or the buffer is too small we have     * to allocate our own     */    if (dwRet == ERROR_MORE_DATA)    {      WCHAR cNull = '/0';      nBytesToAlloc = dwUnExpDataLen;      szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc);      RegQueryValueExW (hKey, lpszValue, 0, NULL, (LPBYTE)szData, &nBytesToAlloc);      dwExpDataLen = ExpandEnvironmentStringsW(szData, &cNull, 1);      dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);      LocalFree(szData);    }    else    {      nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR);      szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc );      lstrcpyW(szData, pvData);      dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, MAX_PATH );      if (dwExpDataLen > MAX_PATH) dwRet = ERROR_MORE_DATA;      dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);      LocalFree(szData);    }  }  RegCloseKey(hKey);  return dwRet;}
开发者ID:MichaelMcDonnell,项目名称:wine,代码行数:50,


示例15: DetourUnhandledExceptionFilter

LONG WINAPI DetourUnhandledExceptionFilter(struct _EXCEPTION_POINTERS* ExceptionInfo){    // 记录用户出错信息    if (NULL != ExceptionInfo)    {        WCHAR szDumpFile[MAX_PATH] = {0};        ExpandEnvironmentStringsW(L"%APPDATA%//MoneyHub//MoneyhubDmp.dmp", szDumpFile, MAX_PATH);        HANDLE hDumpFile = CreateFile(szDumpFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL ,NULL);        MINIDUMP_EXCEPTION_INFORMATION stMiniDumpExceptionInfo;        stMiniDumpExceptionInfo.ExceptionPointers = ExceptionInfo;        stMiniDumpExceptionInfo.ThreadId = GetCurrentThreadId();        stMiniDumpExceptionInfo.ClientPointers = TRUE;        MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile,                          MiniDumpNormal, &stMiniDumpExceptionInfo, NULL, NULL);        CloseHandle(hDumpFile);        DWORD dwAddr = (DWORD)ExceptionInfo->ExceptionRecord->ExceptionAddress;        CRecordProgram::GetInstance()->FeedbackError(MY_ERROR_PRO_CORE, ERR_UNHANDLE_EXCEPT,                CRecordProgram::GetInstance()->GetRecordInfo(L"UnhandledException Errorcode = %d, ErrAddress = %08x", ExceptionInfo->ExceptionRecord->ExceptionCode, dwAddr));        exit(0);        return 0;    }    return OldUnhandledExceptionFilter(ExceptionInfo);}
开发者ID:Williamzuckerberg,项目名称:chtmoneyhub,代码行数:27,


示例16: ExpandEnvVars

UnicodeString ExpandEnvVars(const UnicodeString & Str){  wchar_t buf[MAX_PATH];  intptr_t size = ExpandEnvironmentStringsW(Str.c_str(), buf, static_cast<DWORD>(MAX_PATH - 1));  UnicodeString Result = UnicodeString(buf, size - 1);  return Result;}
开发者ID:CyberShadow,项目名称:Far-NetBox,代码行数:7,


示例17: GetDisplayNameFile

VOIDGetDisplayNameFile(IN LPCWSTR lpLogName,                   OUT PWCHAR lpModuleName){    HKEY hKey;    WCHAR *KeyPath;    WCHAR szModuleName[MAX_PATH];    DWORD cbData;    SIZE_T cbKeyPath;    cbKeyPath = (wcslen(EVENTLOG_BASE_KEY) + wcslen(lpLogName) + 1) * sizeof(WCHAR);    KeyPath = HeapAlloc(GetProcessHeap(), 0, cbKeyPath);    if (!KeyPath)    {        return;    }    StringCbCopyW(KeyPath, cbKeyPath, EVENTLOG_BASE_KEY);    StringCbCatW(KeyPath, cbKeyPath, lpLogName);    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS)    {        HeapFree(GetProcessHeap(), 0, KeyPath);        return;    }    cbData = sizeof(szModuleName);    if (RegQueryValueExW(hKey, L"DisplayNameFile", NULL, NULL, (LPBYTE)szModuleName, &cbData) == ERROR_SUCCESS)    {        ExpandEnvironmentStringsW(szModuleName, lpModuleName, MAX_PATH);    }    RegCloseKey(hKey);    HeapFree(GetProcessHeap(), 0, KeyPath);}
开发者ID:Strongc,项目名称:reactos,代码行数:35,


示例18: CheckValidInstallPath

BOOL CheckValidInstallPath(PCWSTR pszGadgetPath){    BOOL fIsValid = FALSE;    PCWSTR const rgszPaths[] =     {        L"%ProgramFiles%//Windows Sidebar//Gadgets",        L"%ProgramFiles%//Windows Sidebar//Shared Gadgets",        L"%LocalAppData%//Microsoft//Windows Sidebar//Gadgets"    };    for (int iPath = 0; iPath < ARRAYSIZE(rgszPaths); ++iPath)    {        WCHAR szPath[MAX_PATH];        if (ExpandEnvironmentStringsW(rgszPaths[iPath], szPath, ARRAYSIZE(szPath)))        {            if (PathIsPrefixW(szPath, pszGadgetPath))            {                fIsValid = TRUE;                break;            }        }    }    return fIsValid;}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:26,


示例19: load_mapi_provider

/************************************************************************** *  load_mapi_provider * * Attempts to load a MAPI provider from the specified registry key. * * Returns a handle to the loaded module in `mapi_provider' if successful. */static void load_mapi_provider(HKEY hkeyMail, LPCWSTR valueName, HMODULE *mapi_provider){    static const WCHAR mapi32_dll[] = {'m','a','p','i','3','2','.','d','l','l',0 };    DWORD dwType, dwLen = 0;    LPWSTR dllPath;    /* Check if we have a value set for DLLPath */    if ((RegQueryValueExW(hkeyMail, valueName, NULL, &dwType, NULL, &dwLen) == ERROR_SUCCESS) &&        ((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ)) && (dwLen > 0))    {        dllPath = HeapAlloc(GetProcessHeap(), 0, dwLen);        if (dllPath)        {            RegQueryValueExW(hkeyMail, valueName, NULL, NULL, (LPBYTE)dllPath, &dwLen);            /* Check that this value doesn't refer to mapi32.dll (eg, as Outlook does) */            if (lstrcmpiW(dllPath, mapi32_dll) != 0)            {                if (dwType == REG_EXPAND_SZ)                {                    DWORD dwExpandLen;                    LPWSTR dllPathExpanded;                    /* Expand the path if necessary */                    dwExpandLen = ExpandEnvironmentStringsW(dllPath, NULL, 0);                    dllPathExpanded = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * dwExpandLen + 1);                    if (dllPathExpanded)                    {                        ExpandEnvironmentStringsW(dllPath, dllPathExpanded, dwExpandLen + 1);                        HeapFree(GetProcessHeap(), 0, dllPath);                        dllPath = dllPathExpanded;                    }                }                /* Load the DLL */                TRACE("loading %s/n", debugstr_w(dllPath));                *mapi_provider = LoadLibraryW(dllPath);            }            HeapFree(GetProcessHeap(), 0, dllPath);        }    }}
开发者ID:GYGit,项目名称:reactos,代码行数:54,


示例20: open

std::string WinRegistryKey::getStringExpand(const std::string& name){	open();	DWORD type;	DWORD size;#if defined(POCO_WIN32_UTF8)	std::wstring uname;	Poco::UnicodeConverter::toUTF16(name, uname);	if (RegQueryValueExW(_hKey, uname.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ)		throw NotFoundException(key(name));	if (size > 0)	{		DWORD len = size/2;		wchar_t* buffer = new wchar_t[len + 1];		RegQueryValueExW(_hKey, uname.c_str(), NULL, NULL, (BYTE*) buffer, &size);		buffer[len] = 0;		wchar_t temp;		DWORD expSize = ExpandEnvironmentStringsW(buffer, &temp, 1);			wchar_t* expBuffer = new wchar_t[expSize];		ExpandEnvironmentStringsW(buffer, expBuffer, expSize);		std::string result;		UnicodeConverter::toUTF8(expBuffer, result);		delete [] buffer;		delete [] expBuffer;		return result;	}#else	if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS || type != REG_SZ && type != REG_EXPAND_SZ)		throw NotFoundException(key(name));	if (size > 0)	{		char* buffer = new char[size + 1];		RegQueryValueExA(_hKey, name.c_str(), NULL, NULL, (BYTE*) buffer, &size);		buffer[size] = 0;		char temp;		DWORD expSize = ExpandEnvironmentStringsA(buffer, &temp, 1);			char* expBuffer = new char[expSize];		ExpandEnvironmentStringsA(buffer, expBuffer, expSize);		std::string result(expBuffer);		delete [] buffer;		delete [] expBuffer;		return result;	}#endif	return std::string();}
开发者ID:austinsc,项目名称:Poco,代码行数:46,


示例21: load_reg_string

DWORD load_reg_string(HKEY hKey, LPCWSTR szValue, BOOL bExpand, LPWSTR *output){    DWORD size, type;    LPWSTR buf = NULL;    DWORD err;    *output = NULL;    if ((err = RegQueryValueExW(hKey, szValue, 0, &type, NULL, &size)) != 0)    {        if (err == ERROR_FILE_NOT_FOUND)            return ERROR_SUCCESS;        goto failed;    }    if (!(type == REG_SZ || (type == REG_EXPAND_SZ && bExpand)))    {        err = ERROR_INVALID_DATATYPE;        goto failed;    }    buf = HeapAlloc(GetProcessHeap(), 0, size + sizeof(WCHAR));    if ((err = RegQueryValueExW(hKey, szValue, 0, &type, (LPBYTE)buf, &size)) != 0)        goto failed;    buf[size/sizeof(WCHAR)] = 0;    if (type == REG_EXPAND_SZ)    {        LPWSTR str;        DWORD size = ExpandEnvironmentStringsW(buf, NULL, 0);        if (size == 0)        {            err = GetLastError();            goto failed;        }        str = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));        ExpandEnvironmentStringsW(buf, str, size);        HeapFree(GetProcessHeap(), 0, buf);        *output = str;    }    else        *output = buf;    return ERROR_SUCCESS;failed:    WINE_ERR("Error %d while reading value %s/n", err, wine_dbgstr_w(szValue));    HeapFree(GetProcessHeap(), 0, buf);    return err;}
开发者ID:Sunmonds,项目名称:wine,代码行数:46,


示例22: WlxActivateUserShell

/* * @implemented */BOOL WINAPIWlxActivateUserShell(	PVOID pWlxContext,	PWSTR pszDesktopName,	PWSTR pszMprLogonScript,	PVOID pEnvironment){	HKEY hKey;	DWORD BufSize, ValueType;	WCHAR pszUserInitApp[MAX_PATH + 1];	WCHAR pszExpUserInitApp[MAX_PATH];	DWORD len;	LONG rc;	TRACE("WlxActivateUserShell()/n");	UNREFERENCED_PARAMETER(pszMprLogonScript);	/* Get the path of userinit */	rc = RegOpenKeyExW(		HKEY_LOCAL_MACHINE, 		L"SOFTWARE//Microsoft//Windows NT//CurrentVersion//Winlogon",		0,		KEY_QUERY_VALUE,		&hKey);	if (rc != ERROR_SUCCESS)	{		WARN("RegOpenKeyExW() failed with error %lu/n", rc);		return FALSE;	}	/* Query userinit application */	BufSize = sizeof(pszUserInitApp) - sizeof(UNICODE_NULL);	rc = RegQueryValueExW(		hKey,		L"Userinit",		NULL,		&ValueType,		(LPBYTE)pszUserInitApp,		&BufSize);	RegCloseKey(hKey);	if (rc != ERROR_SUCCESS || (ValueType != REG_SZ && ValueType != REG_EXPAND_SZ))	{		WARN("RegQueryValueExW() failed with error %lu/n", rc);		return FALSE;	}	pszUserInitApp[MAX_PATH] = UNICODE_NULL;	len = ExpandEnvironmentStringsW(pszUserInitApp, pszExpUserInitApp, MAX_PATH);	if (len > MAX_PATH)	{		WARN("ExpandEnvironmentStringsW() failed. Required size %lu/n", len);		return FALSE;	}	/* Start userinit app */	return WlxStartApplication(pWlxContext, pszDesktopName, pEnvironment, pszExpUserInitApp);}
开发者ID:HBelusca,项目名称:NasuTek-Odyssey,代码行数:61,


示例23: git_win32__expand_path

static int git_win32__expand_path(_findfile_path *dest, const wchar_t *src){	dest->len = ExpandEnvironmentStringsW(src, dest->path, ARRAY_SIZE(dest->path));	if (!dest->len || dest->len > ARRAY_SIZE(dest->path))		return -1;	return 0;}
开发者ID:GuapoTaco,项目名称:chigraph,代码行数:9,


示例24: GetEventMessageFileDLL

BOOLGetEventMessageFileDLL(IN LPCWSTR lpLogName,                       IN LPCWSTR SourceName,                       IN LPCWSTR EntryName,                       OUT PWCHAR ExpandedName){    DWORD dwSize;    BYTE szModuleName[MAX_PATH];    WCHAR szKeyName[MAX_PATH];    HKEY hAppKey = NULL;    HKEY hSourceKey = NULL;    BOOL bReturn = FALSE;    StringCbCopyW(szKeyName, sizeof(szKeyName), L"SYSTEM//CurrentControlSet//Services//EventLog//");    StringCbCatW(szKeyName, sizeof(szKeyName), lpLogName);    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,                     szKeyName,                     0,                     KEY_READ,                     &hAppKey) == ERROR_SUCCESS)    {        if (RegOpenKeyExW(hAppKey,                         SourceName,                         0,                         KEY_READ,                         &hSourceKey) == ERROR_SUCCESS)        {            dwSize = MAX_PATH;            if (RegQueryValueExW(hSourceKey,                                EntryName,                                NULL,                                NULL,                                (LPBYTE)szModuleName,                                &dwSize) == ERROR_SUCCESS)            {                /* Returns a string containing the requested substituted environment variable. */                ExpandEnvironmentStringsW((LPCWSTR)szModuleName, ExpandedName, MAX_PATH);                /* Successful */                bReturn = TRUE;            }        }    }    else    {        ShowLastWin32Error();    }    if (hSourceKey != NULL)        RegCloseKey(hSourceKey);    if (hAppKey != NULL)        RegCloseKey(hAppKey);    return bReturn;}
开发者ID:Strongc,项目名称:reactos,代码行数:57,


示例25: ExpandVariablesWin

    std::string ExpandVariablesWin(const std::string &path)    {        std::wstring wide;        Multi2Wide(path, wide);        std::wstring buffer;        buffer.resize(MAX_PATH);        DWORD size = ExpandEnvironmentStringsW(wide.c_str(), &buffer[0], buffer.size());        while(size == buffer.size())        {            buffer.resize(buffer.size() * 2);            size = ExpandEnvironmentStringsW(wide.c_str(), &buffer[0], buffer.size());        }        buffer.resize(size);        wide = buffer;        std::string multi;        Wide2Multi(wide, multi);        return multi;    }
开发者ID:evpo,项目名称:EncryptPad,代码行数:19,


示例26: extract_icon

static HICON extract_icon( IShellLinkW *link ){    WCHAR tmp_path[MAX_PATH], icon_path[MAX_PATH], target_path[MAX_PATH];    HICON icon = NULL;    int index;    tmp_path[0] = 0;    IShellLinkW_GetIconLocation( link, tmp_path, MAX_PATH, &index );    ExpandEnvironmentStringsW( tmp_path, icon_path, MAX_PATH );    if (icon_path[0]) ExtractIconExW( icon_path, index, &icon, NULL, 1 );    if (!icon)    {        tmp_path[0] = 0;        IShellLinkW_GetPath( link, tmp_path, MAX_PATH, NULL, SLGP_RAWPATH );        ExpandEnvironmentStringsW( tmp_path, target_path, MAX_PATH );        ExtractIconExW( target_path, index, &icon, NULL, 1 );    }    return icon;}
开发者ID:AmineKhaldi,项目名称:mbedtls-cleanup,代码行数:20,


示例27: ExpandEnvironmentStringsW

/** * generate path where to store settings. * * @note %APPDATA%/Kouets/ *       --> C:/Users/nob-aoki/AppData/Roaming[WinVista/7/8] *       --> C:/Documents and Settings/nob-aoki/Application Data[Win2k/XP] * * @note ~/.Kouets/    on Linux & MacOS */void KouetsApp::prepareAppDataPath(){#ifdef WINDOWS    wchar_t appdatapath[0x1000];    ExpandEnvironmentStringsW(L"%APPDATA%//Kouets//",                              appdatapath, _countof(appdatapath));    appDataPath_ = QString::fromWCharArray(appdatapath);#else    appDataPath_ = "~/.Kouets/";#endif}
开发者ID:o-jill,项目名称:kouets,代码行数:20,


示例28: CreateTempDir

static VOIDCreateTempDir(    IN LPCWSTR VarName){    WCHAR szTempDir[MAX_PATH];    WCHAR szBuffer[MAX_PATH];    DWORD dwLength;    HKEY hKey;    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,                     L"SYSTEM//CurrentControlSet//Control//Session Manager//Environment",                     0,                     KEY_QUERY_VALUE,                     &hKey) != ERROR_SUCCESS)    {        FatalError("Error: %lu/n", GetLastError());        return;    }    /* Get temp dir */    dwLength = MAX_PATH * sizeof(WCHAR);    if (RegQueryValueExW(hKey,                        VarName,                        NULL,                        NULL,                        (LPBYTE)szBuffer,                        &dwLength) != ERROR_SUCCESS)    {        FatalError("Error: %lu/n", GetLastError());        goto cleanup;    }    /* Expand it */    if (!ExpandEnvironmentStringsW(szBuffer,                                  szTempDir,                                  MAX_PATH))    {        FatalError("Error: %lu/n", GetLastError());        goto cleanup;    }    /* Create profiles directory */    if (!CreateDirectoryW(szTempDir, NULL))    {        if (GetLastError() != ERROR_ALREADY_EXISTS)        {            FatalError("Error: %lu/n", GetLastError());            goto cleanup;        }    }cleanup:    RegCloseKey(hKey);}
开发者ID:hoangduit,项目名称:reactos,代码行数:54,


示例29: ExpandEnvironmentStringsForUserW

BOOL WINAPI ExpandEnvironmentStringsForUserW( HANDLE hToken, LPCWSTR lpSrc,                     LPWSTR lpDest, DWORD dwSize ){    BOOL ret;    TRACE("%p %s %p %d/n", hToken, debugstr_w(lpSrc), lpDest, dwSize);    ret = ExpandEnvironmentStringsW( lpSrc, lpDest, dwSize );    TRACE("<- %s/n", debugstr_w(lpDest));    return ret;}
开发者ID:bpon,项目名称:wine,代码行数:11,



注:本文中的ExpandEnvironmentStringsW函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ ExpandPath函数代码示例
C++ ExpandEnvironmentStrings函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。