• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ ExpandEnvironmentStringsW函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了ExpandEnvironmentStringsW函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,代码来源:config.c


示例2: apxExpandStrW

LPWSTR
apxExpandStrW(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,代码来源:utils.c


示例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,代码来源:genviron.c


示例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,代码来源:misc.c


示例5: BuildCommandLine

static size_t
BuildCommandLine(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,代码来源:toolspage.cpp


示例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,代码来源:svchost.c


示例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,代码来源:Updater.cpp


示例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,代码来源:CQueryAssociations.cpp


示例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,代码来源:userenv_main.c


示例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,代码来源:services.c


示例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,代码来源:sysutils.cpp


示例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,代码来源:ConsoleTools.cpp


示例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,代码来源:appsearch.c


示例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,代码来源:system.c


示例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,代码来源:RegMonitor.cpp


示例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,代码来源:Sysutils.cpp


示例17: GetDisplayNameFile

VOID
GetDisplayNameFile(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,代码来源:eventvwr.c


示例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,代码来源:main.cpp


示例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,代码来源:util.c


示例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,代码来源:WinRegistryKey.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ExpandPath函数代码示例发布时间:2022-05-30
下一篇:
C++ ExpandEnvironmentStrings函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap