当前位置: 首页>>代码示例>>C++>>正文


C++ RegSetValueExW函数代码示例

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


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

示例1: AddERExcludedApplicationW

/*************************************************************************
 * AddERExcludedApplicationW  [[email protected]]
 *
 * Adds an application to a list of applications for which fault reports
 * shouldn't be generated
 *
 * PARAMS
 * lpAppFileName  [I] The filename of the application executable
 *
 * RETURNS
 * TRUE on success, FALSE of failure
 *
 * NOTES
 * Wine doesn't use this data but stores it in the registry (in the same place
 * as Windows would) in case it will be useful in a future version
 *
 * According to MSDN this function should succeed even if the user has no write
 * access to HKLM. This probably means that there is no error checking.
 */
BOOL WINAPI AddERExcludedApplicationW(LPCWSTR lpAppFileName)
{
    WCHAR *bslash;
    DWORD value = 1;
    HKEY hkey;

    TRACE("(%s)\n", wine_dbgstr_w(lpAppFileName));
    bslash = strrchrW(lpAppFileName, '\\');
    if (bslash != NULL)
        lpAppFileName = bslash + 1;
    if (*lpAppFileName == '\0')
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    if (!RegCreateKeyW(HKEY_LOCAL_MACHINE, SZ_EXCLUSIONLIST_KEY, &hkey))
    {
        RegSetValueExW(hkey, lpAppFileName, 0, REG_DWORD, (LPBYTE)&value, sizeof(value));
        RegCloseKey(hkey);
    }

    return TRUE;
}
开发者ID:PatroxGaurab,项目名称:wine,代码行数:43,代码来源:faultrep.c

示例2: e3d_set_process_key

HRESULT e3d_set_process_key(const BYTE *key)
{
	if (key_in_process)
		delete key_in_process;

	key_in_process = new unsigned char[32];
	memcpy(key_in_process, key, 32);

	int len = 4;
	wchar_t pid[100];
	wsprintfW(pid, L"%d", GetCurrentProcessId());

	HKEY hkey = NULL;
	int ret = RegCreateKeyExW(HKEY_CURRENT_USER, e3d_soft_key, 0,0,REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS | KEY_WRITE |KEY_SET_VALUE, NULL , &hkey, NULL  );
	if (ret != ERROR_SUCCESS)
		return E_FAIL;
	ret = RegSetValueExW(hkey, pid, 0, REG_BINARY, (const byte*)&key_in_process, len );
	if (ret != ERROR_SUCCESS)
		return E_FAIL;

	RegCloseKey(hkey);

	return S_OK;
}
开发者ID:my12doom,项目名称:personalProjects,代码行数:24,代码来源:E3DReader.cpp

示例3: MainWnd_OnOpenRegKey

void MainWnd_OnOpenRegKey(HWND hwnd)
{
    static const WCHAR s_szRegeditKey[] =
        L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit";
    WCHAR sz[MAX_STRING];

    // open regedit key
    HKEY hKey = NULL;
    LSTATUS Result = RegCreateKeyExW(HKEY_CURRENT_USER, s_szRegeditKey, 0,
                                     NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
    if (Result != ERROR_SUCCESS)
    {
        LoadStringW(g_hInstance, IDS_CANTOPENKEY, sz, _countof(sz));
        MessageBoxW(hwnd, sz, NULL, MB_ICONERROR);
        return;
    }

    // set LastKey value
    wsprintfW(sz, L"HKEY_LOCAL_MACHINE\\%s", g_pszKey);
    DWORD dwSize = sizeof(sz);
    Result = RegSetValueExW(hKey, L"LastKey", 0, REG_SZ,
                                 (LPBYTE)sz, dwSize);

    // close now
    RegCloseKey(hKey);

    if (Result != ERROR_SUCCESS)
    {
        LoadStringW(g_hInstance, IDS_CANTOPENKEY, sz, _countof(sz));
        MessageBoxW(hwnd, sz, NULL, MB_ICONERROR);
        return;
    }

    // open by regedit
    ShellExecuteW(hwnd, NULL, L"regedit.exe", NULL, NULL, SW_SHOWNORMAL);
}
开发者ID:Moteesh,项目名称:reactos,代码行数:36,代码来源:fontsub.cpp

示例4: SetRegistryString

bool SetRegistryString(const char *szSubKey,
                       const char *szValueName,
                       const char *szValue)
{

	long qerr;
	HKEY ckey;
	DWORD disposition;

	// Open the key
	if ((qerr=RegCreateKeyExW(HKEY_CURRENT_USER,
	                         GetWideChar(szSubKey),
	                         0,
	                         L"",
	                         REG_OPTION_NON_VOLATILE,
	                         KEY_ALL_ACCESS,
	                         NULL,
	                         &ckey,
	                         &disposition
	                        ))!=ERROR_SUCCESS) return false;

	// Set the value
	StdBuf v = GetWideCharBuf(szValue);
	if ((qerr=RegSetValueExW(ckey,
	                        GetWideChar(szValueName),
	                        0,
	                        REG_SZ,
	                        getBufPtr<BYTE>(v),
	                        v.getSize()
	                       ))!=ERROR_SUCCESS) { RegCloseKey(ckey); return false; }

	// Close the key
	RegCloseKey(ckey);

	return true;
}
开发者ID:sarah-russell12,项目名称:openclonk,代码行数:36,代码来源:StdRegistry.cpp

示例5: installBrandingValue

static LONG installBrandingValue(MSIHANDLE hModule,
                                 const WCHAR *pwszFileName,
                                 const WCHAR *pwszSection,
                                 const WCHAR *pwszValue)
{
    LONG rc;
    WCHAR wszValue[_MAX_PATH];
    if (GetPrivateProfileStringW(pwszSection, pwszValue, NULL,
                                 wszValue, sizeof(wszValue), pwszFileName) > 0)
    {
        HKEY hkBranding;
        WCHAR wszKey[_MAX_PATH];

        if (wcsicmp(L"General", pwszSection) != 0)
            swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding\\", VBOX_VENDOR_SHORT, pwszSection);
        else
            swprintf_s(wszKey, RT_ELEMENTS(wszKey), L"SOFTWARE\\%s\\VirtualBox\\Branding", VBOX_VENDOR_SHORT);

        rc = RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszKey, 0, KEY_WRITE, &hkBranding);
        if (rc == ERROR_SUCCESS)
        {
            rc = RegSetValueExW(hkBranding,
                                pwszValue,
                                NULL,
                                REG_SZ,
                                (BYTE *)wszValue,
                                (DWORD)wcslen(wszValue));
            if (rc != ERROR_SUCCESS)
                logStringW(hModule, L"InstallBranding: Could not write value %s! Error %ld", pwszValue, rc);
            RegCloseKey (hkBranding);
        }
    }
    else
        rc = ERROR_NOT_FOUND;
    return rc;
}
开发者ID:bayasist,项目名称:vbox,代码行数:36,代码来源:VBoxInstallHelper.cpp

示例6: stillimagew_RegisterLaunchApplication

static HRESULT WINAPI stillimagew_RegisterLaunchApplication(IStillImageW *iface, LPWSTR pwszAppName,
                                                            LPWSTR pwszCommandLine)
{
    static const WCHAR format[] = {'%','s',' ','%','s',0};
    static const WCHAR commandLineSuffix[] = {
        '/','S','t','i','D','e','v','i','c','e',':','%','1',' ',
        '/','S','t','i','E','v','e','n','t',':','%','2',0};
    HKEY registeredAppsKey = NULL;
    DWORD ret;
    HRESULT hr = S_OK;
    stillimage *This = impl_from_IStillImageW(iface);

    TRACE("(%p, %s, %s)\n", This, debugstr_w(pwszAppName), debugstr_w(pwszCommandLine));

    ret = RegCreateKeyW(HKEY_LOCAL_MACHINE, registeredAppsLaunchPath, &registeredAppsKey);
    if (ret == ERROR_SUCCESS)
    {
        WCHAR *value = HeapAlloc(GetProcessHeap(), 0,
            (lstrlenW(pwszCommandLine) + 1 + lstrlenW(commandLineSuffix) + 1) * sizeof(WCHAR));
        if (value)
        {
            sprintfW(value, format, pwszCommandLine, commandLineSuffix);
            ret = RegSetValueExW(registeredAppsKey, pwszAppName, 0,
                REG_SZ, (BYTE*)value, (lstrlenW(value)+1)*sizeof(WCHAR));
            if (ret != ERROR_SUCCESS)
                hr = HRESULT_FROM_WIN32(ret);
            HeapFree(GetProcessHeap(), 0, value);
        }
        else
            hr = E_OUTOFMEMORY;
        RegCloseKey(registeredAppsKey);
    }
    else
        hr = HRESULT_FROM_WIN32(ret);
    return hr;
}
开发者ID:AlexSteel,项目名称:wine,代码行数:36,代码来源:sti.c

示例7: setValue

/******************************************************************************
 * Sets the value with name val_name to the data in val_data for the currently
 * opened key.
 *
 * Parameters:
 * val_name - name of the registry value
 * val_data - registry value data
 */
static LONG setValue(WCHAR* val_name, WCHAR* val_data, BOOL is_unicode)
{
    LONG res;
    DWORD  dwDataType, dwParseType;
    LPBYTE lpbData;
    DWORD  dwData, dwLen;
    WCHAR del[] = {'-',0};

    if ( (val_name == NULL) || (val_data == NULL) )
        return ERROR_INVALID_PARAMETER;

    if (lstrcmpW(val_data, del) == 0)
    {
        res=RegDeleteValueW(currentKeyHandle,val_name);
        return (res == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : res);
    }

    /* Get the data type stored into the value field */
    dwDataType = getDataType(&val_data, &dwParseType);

    if (dwParseType == REG_SZ)          /* no conversion for string */
    {
        REGPROC_unescape_string(val_data);
        /* Compute dwLen after REGPROC_unescape_string because it may
         * have changed the string length and we don't want to store
         * the extra garbage in the registry.
         */
        dwLen = lstrlenW(val_data);
        if(val_data[dwLen-1] != '"')
            return ERROR_INVALID_DATA;
        if (dwLen>0 && val_data[dwLen-1]=='"')
        {
            dwLen--;
            val_data[dwLen]='\0';
        }
        lpbData = (BYTE*) val_data;
        dwLen++;  /* include terminating null */
        dwLen = dwLen * sizeof(WCHAR); /* size is in bytes */
    }
    else if (dwParseType == REG_DWORD)  /* Convert the dword types */
    {
        if (!convertHexToDWord(val_data, &dwData))
            return ERROR_INVALID_DATA;
        lpbData = (BYTE*)&dwData;
        dwLen = sizeof(dwData);
    }
    else if (dwParseType == REG_BINARY) /* Convert the binary data */
    {
        lpbData = convertHexCSVToHex(val_data, &dwLen);
        if (!lpbData)
            return ERROR_INVALID_DATA;

        if((dwDataType == REG_MULTI_SZ || dwDataType == REG_EXPAND_SZ) && !is_unicode)
        {
            LPBYTE tmp = lpbData;
            lpbData = (LPBYTE)GetWideStringN((char*)lpbData, dwLen, &dwLen);
            dwLen *= sizeof(WCHAR);
            HeapFree(GetProcessHeap(), 0, tmp);
        }
    }
    else                                /* unknown format */
    {
        fprintf(stderr,"%s: ERROR, unknown data format\n", getAppName());
        return ERROR_INVALID_DATA;
    }

    res = RegSetValueExW(
               currentKeyHandle,
               val_name,
               0,                  /* Reserved */
               dwDataType,
               lpbData,
               dwLen);
    if (dwParseType == REG_BINARY)
        HeapFree(GetProcessHeap(), 0, lpbData);
    return res;
}
开发者ID:DeltaYang,项目名称:wine,代码行数:85,代码来源:regproc.c

示例8: RegistryRemoveStringFromMultiSZ

/**
 * Removes a string entry from a MULTI_SZ registry list.
 *
 * @return  Exit code (EXIT_OK, EXIT_FAIL)
 * @param   pszSubKey           Sub key containing the list.
 * @param   pszKeyValue         The actual key name of the list.
 * @param   pszValueToRemove    The value to remove from the list.
 */
int RegistryRemoveStringFromMultiSZ(const TCHAR *pszSubKey, const TCHAR *pszKeyValue, const TCHAR *pszValueToRemove)
{
    // @todo Make string sizes dynamically allocated!

    const TCHAR *pszKey = pszSubKey;
#ifdef DEBUG
    _tprintf(_T("RemoveStringFromMultiSZ: Removing MULTI_SZ string: %ws from %ws\\%ws ...\n"), pszValueToRemove, pszSubKey, pszKeyValue);
#endif

    HKEY hkey;
    DWORD disp, dwType;
    LONG lRet = RegCreateKeyEx(HKEY_LOCAL_MACHINE, pszKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ | KEY_WRITE, NULL, &hkey, &disp);
    if (lRet != ERROR_SUCCESS)
        _tprintf(_T("RemoveStringFromMultiSZ: RegCreateKeyEx %ts failed with error %ld!\n"), pszKey, lRet);

    if (lRet == ERROR_SUCCESS)
    {
        TCHAR szKeyValue[1024];
        DWORD cbKeyValue = sizeof(szKeyValue);

        lRet = RegQueryValueEx(hkey, pszKeyValue, NULL, &dwType, (LPBYTE)szKeyValue, &cbKeyValue);
        if (   lRet   != ERROR_SUCCESS
            || dwType != REG_MULTI_SZ)
        {
            _tprintf(_T("RemoveStringFromMultiSZ: RegQueryValueEx failed with %d, key type = 0x%x!\n"), lRet, dwType);
        }
        else
        {
        #ifdef DEBUG
            _tprintf(_T("RemoveStringFromMultiSZ: Current key len: %ld\n"), cbKeyValue);
        #endif

            TCHAR szCurString[1024] = { 0 };
            TCHAR szFinalString[1024] = { 0 };
            int iIndex = 0;
            int iNewIndex = 0;
            for (unsigned i = 0; i < cbKeyValue / sizeof(TCHAR); i++)
            {
                if (szKeyValue[i] != _T('\0'))
                    szCurString[iIndex++] = szKeyValue[i];

                if (   (!szKeyValue[i] == _T('\0'))
                    && (szKeyValue[i + 1] == _T('\0')))
                {
                    if (NULL == wcsstr(szCurString, pszValueToRemove))
                    {
                        wcscat(&szFinalString[iNewIndex], szCurString);

                        if (iNewIndex == 0)
                            iNewIndex = iIndex;
                        else iNewIndex += iIndex;

                        szFinalString[++iNewIndex] = _T('\0');
                    }

                    iIndex = 0;
                    ZeroMemory(szCurString, sizeof(szCurString));
                }
            }
            szFinalString[++iNewIndex] = _T('\0');
        #ifdef DEBUG
            _tprintf(_T("RemoveStringFromMultiSZ: New key value: %ws (%u bytes)\n"),
                     szFinalString, iNewIndex * sizeof(TCHAR));
        #endif

            lRet = RegSetValueExW(hkey, pszKeyValue, 0, REG_MULTI_SZ, (LPBYTE)szFinalString, iNewIndex * sizeof(TCHAR));
            if (lRet != ERROR_SUCCESS)
                _tprintf(_T("RemoveStringFromMultiSZ: RegSetValueEx failed with %d!\n"), lRet);
        }

        RegCloseKey(hkey);
    #ifdef DEBUG
        if (lRet == ERROR_SUCCESS)
            _tprintf(_T("RemoveStringFromMultiSZ: Value %ws successfully removed!\n"), pszValueToRemove);
    #endif
    }

    return (lRet == ERROR_SUCCESS) ? EXIT_OK : EXIT_FAIL;
}
开发者ID:ElvisTulip,项目名称:vbox,代码行数:87,代码来源:VBoxDrvInst.cpp

示例9: CopyKey


//.........这里部分代码省略.........
                HeapFree (GetProcessHeap (),
                          0,
                          lpNameBuffer);
                return FALSE;
            }

            RegCloseKey (hSrcSubKey);
            RegCloseKey (hDstSubKey);
        }

        HeapFree (GetProcessHeap (),
                  0,
                  lpNameBuffer);
    }

    /* Copy values */
    if (dwValues != 0)
    {
        lpNameBuffer = HeapAlloc (GetProcessHeap (),
                                  0,
                                  dwMaxValueNameLength * sizeof(WCHAR));
        if (lpNameBuffer == NULL)
        {
            DPRINT1 ("Buffer allocation failed\n");
            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
            return FALSE;
        }

        lpDataBuffer = HeapAlloc (GetProcessHeap (),
                                  0,
                                  dwMaxValueLength);
        if (lpDataBuffer == NULL)
        {
            DPRINT1 ("Buffer allocation failed\n");
            HeapFree (GetProcessHeap (),
                      0,
                      lpNameBuffer);
            SetLastError(ERROR_NOT_ENOUGH_MEMORY);
            return FALSE;
        }

        for (i = 0; i < dwValues; i++)
        {
            dwValueNameLength = dwMaxValueNameLength;
            dwValueLength = dwMaxValueLength;
            Error = RegEnumValueW (hSrcKey,
                                   i,
                                   lpNameBuffer,
                                   &dwValueNameLength,
                                   NULL,
                                   &dwType,
                                   lpDataBuffer,
                                   &dwValueLength);
            if (Error != ERROR_SUCCESS)
            {
                DPRINT1("Error: %lu\n", Error);
                HeapFree (GetProcessHeap (),
                          0,
                          lpDataBuffer);
                HeapFree (GetProcessHeap (),
                          0,
                          lpNameBuffer);
                SetLastError((DWORD)Error);
                return FALSE;
            }

            Error = RegSetValueExW (hDstKey,
                                    lpNameBuffer,
                                    0,
                                    dwType,
                                    lpDataBuffer,
                                    dwValueLength);
            if (Error != ERROR_SUCCESS)
            {
                DPRINT1("Error: %lu\n", Error);
                HeapFree (GetProcessHeap (),
                          0,
                          lpDataBuffer);
                HeapFree (GetProcessHeap (),
                          0,
                          lpNameBuffer);
                SetLastError((DWORD)Error);
                return FALSE;
            }
        }

        HeapFree (GetProcessHeap (),
                  0,
                  lpDataBuffer);

        HeapFree (GetProcessHeap (),
                  0,
                  lpNameBuffer);
    }

    DPRINT ("CopyKey() done \n");

    return TRUE;
#endif
}
开发者ID:HBelusca,项目名称:NasuTek-Odyssey,代码行数:101,代码来源:registry.c

示例10: ComDBReleasePort

LONG
WINAPI
ComDBReleasePort(IN HCOMDB hComDB,
                 IN DWORD ComNumber)
{
    PCOMDB pComDB;
    DWORD dwByteIndex;
    DWORD dwBitIndex;
    DWORD dwType;
    DWORD dwSize;
    PBYTE pBitmap = NULL;
    BYTE cMask;
    LONG lError;

    TRACE("ComDBReleasePort(%p %lu)\n", hComDB, ComNumber);

    if (hComDB == INVALID_HANDLE_VALUE ||
        ComNumber == 0 ||
        ComNumber > COMDB_MAX_PORTS_ARBITRATED)
        return ERROR_INVALID_PARAMETER;

    pComDB = (PCOMDB)hComDB;

    /* Wait for the mutex */
    WaitForSingleObject(pComDB->hMutex, INFINITE);

    /* Get the required bitmap size */
    lError = RegQueryValueExW(pComDB->hKey,
                              L"ComDB",
                              NULL,
                              &dwType,
                              NULL,
                              &dwSize);
    if (lError != ERROR_SUCCESS)
    {
        ERR("Failed to query the bitmap size!\n");
        goto done;
    }

    /* Allocate the bitmap */
    pBitmap = HeapAlloc(GetProcessHeap(),
                        HEAP_ZERO_MEMORY,
                        dwSize);
    if (pBitmap == NULL)
    {
        ERR("Failed to allocate the bitmap!\n");
        lError = ERROR_NOT_ENOUGH_MEMORY;
        goto done;
    }

    /* Read the bitmap */
    lError = RegQueryValueExW(pComDB->hKey,
                              L"ComDB",
                              NULL,
                              &dwType,
                              pBitmap,
                              &dwSize);
    if (lError != ERROR_SUCCESS)
        goto done;

    /* Get the bit index */
    dwBitIndex = ComNumber - 1;

    /* Check if the bit to set fits into the bitmap */
    if (dwBitIndex >= (dwSize * BITS_PER_BYTE))
    {
        lError = ERROR_INVALID_PARAMETER;
        goto done;
    }

    /* Calculate the byte index and a mask for the affected bit */
    dwByteIndex = dwBitIndex / BITS_PER_BYTE;
    cMask = 1 << (dwBitIndex % BITS_PER_BYTE);

    /* Release the port */
    pBitmap[dwByteIndex] &= ~cMask;

    lError = RegSetValueExW(pComDB->hKey,
                            L"ComDB",
                            0,
                            REG_BINARY,
                            pBitmap,
                            dwSize);

done:;
    /* Release the mutex */
    ReleaseMutex(pComDB->hMutex);

    /* Release the bitmap */
    if (pBitmap != NULL)
        HeapFree(GetProcessHeap(), 0, pBitmap);

    return lError;
}
开发者ID:hoangduit,项目名称:reactos,代码行数:94,代码来源:comdb.c

示例11: ComDBClaimNextFreePort

LONG
WINAPI
ComDBClaimNextFreePort(IN HCOMDB hComDB,
                       OUT LPDWORD ComNumber)
{
    PCOMDB pComDB;
    DWORD dwBitIndex;
    DWORD dwByteIndex;
    DWORD dwSize;
    DWORD dwType;
    PBYTE pBitmap = NULL;
    BYTE cMask;
    LONG lError;

    TRACE("ComDBClaimNextFreePort(%p %p)\n", hComDB, ComNumber);

    if (hComDB == INVALID_HANDLE_VALUE ||
        hComDB == NULL ||
        ComNumber == NULL)
        return ERROR_INVALID_PARAMETER;

    pComDB = (PCOMDB)hComDB;

    /* Wait for the mutex */
    WaitForSingleObject(pComDB->hMutex, INFINITE);

    /* Get the required bitmap size */
    lError = RegQueryValueExW(pComDB->hKey,
                              L"ComDB",
                              NULL,
                              &dwType,
                              NULL,
                              &dwSize);
    if (lError != ERROR_SUCCESS)
    {
        ERR("Failed to query the bitmap size!\n");
        goto done;
    }

    /* Allocate the bitmap */
    pBitmap = HeapAlloc(GetProcessHeap(),
                        HEAP_ZERO_MEMORY,
                        dwSize);
    if (pBitmap == NULL)
    {
        ERR("Failed to allocate the bitmap!\n");
        lError = ERROR_NOT_ENOUGH_MEMORY;
        goto done;
    }

    /* Read the bitmap */
    lError = RegQueryValueExW(pComDB->hKey,
                              L"ComDB",
                              NULL,
                              &dwType,
                              pBitmap,
                              &dwSize);
    if (lError != ERROR_SUCCESS)
        goto done;

    lError = ERROR_INVALID_PARAMETER;
    for (dwBitIndex = 0; dwBitIndex < (dwSize * BITS_PER_BYTE); dwBitIndex++)
    {
        /* Calculate the byte index and a mask for the affected bit */
        dwByteIndex = dwBitIndex / BITS_PER_BYTE;
        cMask = 1 << (dwBitIndex % BITS_PER_BYTE);

        if ((pBitmap[dwByteIndex] & cMask) == 0)
        {
            pBitmap[dwByteIndex] |= cMask;
            *ComNumber = dwBitIndex + 1;
             lError = ERROR_SUCCESS;
             break;
        }
    }

    /* Save the bitmap if it was modified */
    if (lError == ERROR_SUCCESS)
    {
        lError = RegSetValueExW(pComDB->hKey,
                                L"ComDB",
                                0,
                                REG_BINARY,
                                pBitmap,
                                dwSize);
    }

done:;
    /* Release the mutex */
    ReleaseMutex(pComDB->hMutex);

    /* Release the bitmap */
    if (pBitmap != NULL)
        HeapFree(GetProcessHeap(), 0, pBitmap);

    return lError;
}
开发者ID:hoangduit,项目名称:reactos,代码行数:97,代码来源:comdb.c

示例12: set_reg_value

/* wrapper for RegSetValueExW */
static DWORD set_reg_value( HKEY hkey, const WCHAR *name, const WCHAR *value )
{
    return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, (strlenW(value) + 1) * sizeof(WCHAR) );
}
开发者ID:klickverbot,项目名称:wine,代码行数:5,代码来源:wineboot.c

示例13: DisableNetworkAdapter

VOID
DisableNetworkAdapter(INetConnection * pNet, LANSTATUSUI_CONTEXT * pContext, HWND hwndDlg)
{
    HKEY hKey;
    NETCON_PROPERTIES * pProperties;
    LPOLESTR pDisplayName;
    WCHAR szPath[200];
    DWORD dwSize, dwType;
    LPWSTR pPnp;
    HDEVINFO hInfo;
    SP_DEVINFO_DATA DevInfo;
    SP_PROPCHANGE_PARAMS PropChangeParams;
    BOOL bClose = FALSE;
    NOTIFYICONDATAW nid;

    if (FAILED(pNet->GetProperties(&pProperties)))
        return;


    hInfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT );
    if (!hInfo)
    {
        NcFreeNetconProperties(pProperties);
        return;
    }

    if (FAILED(StringFromCLSID((CLSID)pProperties->guidId, &pDisplayName)))
    {
        NcFreeNetconProperties(pProperties);
        SetupDiDestroyDeviceInfoList(hInfo);
        return;
    }
    NcFreeNetconProperties(pProperties);

    if (FindNetworkAdapter(hInfo, &DevInfo, pDisplayName))
    {
        PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
        PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; //;
        PropChangeParams.StateChange = DICS_DISABLE;
        PropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC;
        PropChangeParams.HwProfile = 0;

        if (SetupDiSetClassInstallParams(hInfo, &DevInfo, &PropChangeParams.ClassInstallHeader, sizeof(SP_PROPCHANGE_PARAMS)))
        {
            if (SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hInfo, &DevInfo))
                bClose = TRUE;
        }
    }
    SetupDiDestroyDeviceInfoList(hInfo);

    swprintf(szPath, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", pDisplayName);
    CoTaskMemFree(pDisplayName);

    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
        return;

    dwSize = 0;
    if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, NULL, &dwSize) != ERROR_SUCCESS || dwType != REG_SZ)
    {
        RegCloseKey(hKey);
        return;
    }

    pPnp = static_cast<PWSTR>(CoTaskMemAlloc(dwSize));
    if (!pPnp)
    {
        RegCloseKey(hKey);
        return;
    }

    if (RegQueryValueExW(hKey, L"PnpInstanceID", NULL, &dwType, (LPBYTE)pPnp, &dwSize) != ERROR_SUCCESS)
    {
        CoTaskMemFree(pPnp);
        RegCloseKey(hKey);
        return;
    }
    RegCloseKey(hKey);

    swprintf(szPath, L"System\\CurrentControlSet\\Hardware Profiles\\Current\\System\\CurrentControlSet\\Enum\\%s", pPnp);
    CoTaskMemFree(pPnp);

    if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szPath, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS)
        return;

    dwSize = 1; /* enable = 0, disable = 1 */
    RegSetValueExW(hKey, L"CSConfigFlags", 0, REG_DWORD, (LPBYTE)&dwSize, sizeof(DWORD));
    RegCloseKey(hKey);

    if (!bClose)
       return;

    PropSheet_PressButton(GetParent(hwndDlg), PSBTN_CANCEL);
    ZeroMemory(&nid, sizeof(nid));
    nid.cbSize = sizeof(nid);
    nid.uID = pContext->uID;
    nid.hWnd = pContext->hwndDlg;
    nid.uFlags = NIF_STATE;
    nid.dwState = NIS_HIDDEN;
    nid.dwStateMask = NIS_HIDDEN;

//.........这里部分代码省略.........
开发者ID:GYGit,项目名称:reactos,代码行数:101,代码来源:lanstatusui.cpp

示例14: DeleteFromMultiSzValue

LONG
DeleteFromMultiSzValue (
    HKEY hkeyAdapterGuid,
    _In_ LPWSTR szMiniportGuid)
{
    LPWSTR lpCurrentValue=NULL;
    LPWSTR lpNewValue=NULL;
    LPWSTR lpCurrentValueTemp;
    LPWSTR lpNewValueTemp;
    DWORD  dwLen;
    DWORD  dwNewLen;
    LONG   lResult;

    dwLen = 0;
    lResult =  RegQueryValueExW(
                        hkeyAdapterGuid,
                        c_szUpperBindings,
                        NULL,
                        NULL,
                        NULL,
                        &dwLen );

    if ( lResult == ERROR_SUCCESS ) {
        lpCurrentValue = (LPWSTR)calloc( dwLen, 1 );
        lpNewValue = (LPWSTR)calloc( dwLen, 1 );

        if ( (lpCurrentValue != NULL) && (lpNewValue != NULL) ) {

            lResult =  RegQueryValueExW(
                              hkeyAdapterGuid,
                              c_szUpperBindings,
                              NULL,
                              NULL,
                              (LPBYTE)lpCurrentValue,
                              &dwLen );

            if ( lResult == ERROR_SUCCESS ) {

                lpCurrentValueTemp = lpCurrentValue;
                lpNewValueTemp = lpNewValue;

                dwNewLen = 0;

                lpCurrentValueTemp[dwLen-1]='\0';
                while( wcslen(lpCurrentValueTemp) > 0) {

                    //if a register in the existing register sequence do not match szMiniportGuid, copy to new register sequence 
                    if ( _wcsicmp(lpCurrentValueTemp, szMiniportGuid) != 0 ) {
                        StringCchCopyW ( lpNewValueTemp,
                        wcslen(lpCurrentValueTemp), //size of the register
                        lpCurrentValueTemp );
                                                
                        *(lpNewValueTemp+=wcslen(lpCurrentValueTemp)+1)='\0';
                        
                        lpNewValueTemp += wcslen(lpNewValueTemp) + 1;
                        dwNewLen += (DWORD)wcslen(lpNewValueTemp) + 1;
                    }

                    lpCurrentValueTemp += wcslen(lpCurrentValueTemp) + 1;
                } //end of while

                //the minimum length of a register sequence is 3 (start with '\\' and end with '\0') eg: '\\','a','\0'
                if ( dwNewLen > 2 ) {
                    lResult = RegSetValueExW( hkeyAdapterGuid,
                                          c_szUpperBindings,
                                          0,
                                          REG_MULTI_SZ,
                                          (LPBYTE)lpNewValue,
                                          dwNewLen );
                }
                else {
                    lResult = RegDeleteValueW( hkeyAdapterGuid,
                                               c_szUpperBindings );
                }
            }
        }
        else {
            lResult = ERROR_NOT_ENOUGH_MEMORY;
        }
    }

    if ( lpCurrentValue ) {
        free( lpCurrentValue );
    }

    if ( lpNewValue ) {
        free( lpNewValue );
    }

    return lResult;
}
开发者ID:340211173,项目名称:Driver,代码行数:91,代码来源:common.cpp

示例15: AddToMultiSzValue

LONG
AddToMultiSzValue (
    HKEY hkeyAdapterGuid,
    _In_ LPWSTR szMiniportGuid)
{
    LPWSTR lpCurrentValue=NULL;
    LPWSTR lpNewValue=NULL;
    DWORD  dwLen;
    DWORD  dwNewLen;
    LONG   lResult;

    dwLen = 0;
    lResult =  RegQueryValueExW(
                        hkeyAdapterGuid,
                        c_szUpperBindings,
                        NULL,
                        NULL,
                        NULL,
                        &dwLen );
    if( lResult != ERROR_SUCCESS ){
       //you may do something
    }

    if ( dwLen != 0 ) {
        lpCurrentValue = (LPWSTR)calloc( dwLen, 1 );

        if ( lpCurrentValue ) {

        lResult =  RegQueryValueExW( hkeyAdapterGuid,
                                     c_szUpperBindings,
                                     NULL,
                                     NULL,
                                     (LPBYTE)lpCurrentValue,
                                     &dwLen );

        }
        else {

            lResult = ERROR_NOT_ENOUGH_MEMORY;
        }
    }
    else {
        dwLen = sizeof(WCHAR);
        lpCurrentValue = (LPWSTR)calloc( dwLen, 1 );

        if ( !lpCurrentValue ) {
            lResult = ERROR_NOT_ENOUGH_MEMORY;
        }
        else {
            lResult = ERROR_SUCCESS;
        }
    }

    if ( lResult == ERROR_SUCCESS ) {

        dwNewLen =(DWORD) (dwLen + ((wcslen(szMiniportGuid) + 1) * sizeof(WCHAR)));

        lpNewValue = (LPWSTR)malloc( dwNewLen );

        if ( lpNewValue ) {

            StringCbCopyW ( lpNewValue,
                dwNewLen,
                szMiniportGuid );

            CopyMemory( lpNewValue+wcslen(szMiniportGuid)+1,
                        lpCurrentValue,
                        dwLen );

            lResult = RegSetValueExW( hkeyAdapterGuid,
                                    c_szUpperBindings,
                                    0,
                                    REG_MULTI_SZ,
                                    (LPBYTE)lpNewValue,
                                    dwNewLen );
        }
        else {
            lResult = ERROR_NOT_ENOUGH_MEMORY;
        }
    }

    if ( lpCurrentValue ) {

#ifndef DISABLE_PREFAST_PRAGMA
#pragma prefast(suppress:__WARNING_MISSING_ZERO_TERMINATION, "lpCurrentValue is used as a counted string.")
#endif

        free( lpCurrentValue );
    }

    if ( lpNewValue ) {
        free( lpNewValue );
    }

    return lResult;
}
开发者ID:340211173,项目名称:Driver,代码行数:96,代码来源:common.cpp


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