Exemple #1
0
static
void
create_ramdisk_hardware_keys(HDEVINFO device_info_set,
                             PSP_DEVINFO_DATA device_info_data) {
  // we allow the ramdisk to use 1/5 of the commit limit
  // (the commit limit shouldn't be larger than the largest DWORD
  //  value)
  auto ramdisk_size =
    (DWORD) std::min(query_commit_limit() / 5ULL,
                     (ULONGLONG) MAXDWORD);

  // NB: at the point we are at in the installation, we have not
  // yet installed the driver, so we must use a "hardware key"
  auto hkey = SetupDiCreateDevRegKey(device_info_set,
                                     device_info_data,
                                     DICS_FLAG_GLOBAL,
                                     0,
                                     DIREG_DEV,
                                     nullptr,
                                     nullptr);
  if (hkey == INVALID_HANDLE_VALUE) w32util::throw_setupapi_error();

  auto _close_key = safe::create_deferred(RegCloseKey, hkey);

  auto ret = RegSetValueEx(hkey,
                           SAFE_RAMDISK_SIZE_VALUE_NAME_W,
                           0,
                           REG_DWORD,
                           (BYTE *) &ramdisk_size,
                           sizeof(ramdisk_size));
  if (ret != ERROR_SUCCESS) w32util::throw_windows_error();
}
Exemple #2
0
LONG SetPortNum(
    HDEVINFO hDevInfo,
    PSP_DEVINFO_DATA pDevInfoData,
    int num)
{
  HKEY hKey;

  hKey = SetupDiCreateDevRegKey(hDevInfo, pDevInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, NULL, NULL);

  if (hKey == INVALID_HANDLE_VALUE)
    return GetLastError();

  DWORD portNum = num;

  LONG err = RegSetValueEx(hKey, C0C_REGSTR_VAL_PORT_NUM, NULL, REG_DWORD, (PBYTE)&portNum, sizeof(portNum));

  RegCloseKey(hKey);

  return err;
}
Exemple #3
0
BOOL SetFilterAffinityMask( HDEVINFO hDevInfo,
                            PSP_DEVINFO_DATA pDevInfoData,
                            DWORD affinityMask )
{
    HKEY hkeyDeviceParams;
    LONG lRetVal;
    BOOL fToReturn = TRUE;  // success


    //
    // Get a handle to the device's "Device Parameters" registry subkey
    //
    hkeyDeviceParams = SetupDiOpenDevRegKey( hDevInfo,
                                             pDevInfoData,
                                             DICS_FLAG_GLOBAL,  //CPRINCE: SHOULD (CAN?) USE 'DICS_FLAG_CONFIGSPECIFIC' INSTEAD ???
                                             0,
                                             DIREG_DEV,
                                             KEY_WRITE  // desired access
                                           );

    if( INVALID_HANDLE_VALUE == hkeyDeviceParams )
    {
        // Error opening device registry key...
        //
        // If error occurred because "Device Parameters" sub-key does
        // not exist, then try to create that sub-key.

        // NOTE: when we call GetLastError() here, we're getting an invalid
        // error code.  So let's just _assume_ (yeah, I know) that the error
        // was because the key does not exist, and try to create it here.

        hkeyDeviceParams = SetupDiCreateDevRegKey( hDevInfo,
                                                   pDevInfoData,
                                                   DICS_FLAG_GLOBAL,  //CPRINCE: SHOULD (CAN?) USE 'DICS_FLAG_CONFIGSPECIFIC' INSTEAD ???
                                                   0,
                                                   DIREG_DEV,
                                                   NULL,
                                                   NULL
                                                 );
        if( INVALID_HANDLE_VALUE == hkeyDeviceParams )
        {
            // OK, we can't open and can't create the key.  Let's
            // face it, we've failed, so return now.
            //MessageBox_FromErrorCode( GetLastError() );
            return FALSE;
        }
        //ELSE: we were able to create the key, so keep going...
    }


    //
    // Set the desired registry value
    //
    lRetVal = RegSetValueEx( hkeyDeviceParams,
                             FILTER_REGISTRY_VALUE,
                             0,
                             REG_DWORD,
                             (BYTE*)&affinityMask,
                             sizeof(DWORD)
                           );

    if( ERROR_SUCCESS != lRetVal )
    {
        //MessageBox_FromErrorCode( lRetVal );
        fToReturn = FALSE;  // failure
    }


    //
    // Close the registry key(s) we opened
    //
    lRetVal = RegCloseKey( hkeyDeviceParams );
    if( ERROR_SUCCESS != lRetVal )
    {
        //MessageBox_FromErrorCode( lRetVal );
        fToReturn = FALSE;  // failure
    }


    return fToReturn;
}