⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 irclass.c

📁 This sample demonstrates the handling of DIF_ calls during device installation and the insertion of
💻 C
📖 第 1 页 / 共 4 页
字号:
             dwType=REG_SZ;
             RegEnumValue(hkSerialComm,
                          i,
                          Value,
                          &ValueLength,
                          NULL,
                          &dwType,
                          (LPBYTE)Data,
                          &DataLength
                         )==ERROR_SUCCESS;
            i++, dwType==REG_SZ
            )
        {
            if (dwType==REG_SZ)
            {
                (*pNumFound)++;
                SendDlgItemMessage(hDlg,
                                   IDC_PORT,
                                   LB_ADDSTRING,
                                   0,
                                   (LPARAM)Data);

            }

            ValueLength = sizeof(Value);
            DataLength = sizeof(Data);
        }

        lResult = SendDlgItemMessage(hDlg,
                                     IDC_PORT,
                                     LB_FINDSTRINGEXACT,
                                     0,
                                     (LPARAM)CurrentPort);
        if (lResult==LB_ERR)
        {
            i = 0;
            pPropParams->PortInitialValue = -1;
        }
        else
        {
            i = (DWORD)lResult;
            pPropParams->PortInitialValue = i;
        }

        SendDlgItemMessage(hDlg,
                           IDC_PORT,
                           LB_SETCURSEL,
                           i,
                           0);
    }

    if (CurrentPort)
    {
        LocalFree(CurrentPort);
    }

    if (hkSerialComm!=INVALID_HANDLE_VALUE)
    {
        RegCloseKey(hkSerialComm);
    }

    if (hKey!=INVALID_HANDLE_VALUE)
    {
        RegCloseKey(hKey);
    }

    return Result;
}

BOOL
IsPortValueSet(
              IN     HDEVINFO                     DeviceInfoSet,
              IN     PSP_DEVINFO_DATA             DeviceInfoData
             )
{
    HKEY hKey = INVALID_HANDLE_VALUE;
    BOOL bResult = FALSE;
    LPTSTR CurrentPort = NULL;
    DWORD dwLength;
    LONG Result;

    hKey = SetupDiOpenDevRegKey(DeviceInfoSet,
                                DeviceInfoData,
                                DICS_FLAG_GLOBAL,
                                0,
                                DIREG_DRV,
                                KEY_ALL_ACCESS);

    if (hKey != INVALID_HANDLE_VALUE)
    {
        // Read the current port.  If it's empty, we'll start with an empty value.
        // Failure is ok.

        Result = MyRegQueryValueEx(hKey,
                                   TEXT("Port"),
                                   NULL,
                                   NULL,
                                   (LPBYTE*)&CurrentPort,
                                   &dwLength);

        if (Result == ERROR_SUCCESS && CurrentPort!=NULL)
        {
            bResult = TRUE;
            LocalFree(CurrentPort);
        }

        RegCloseKey(hKey);
    }
    return bResult;
}

LONG
InitMaxConnect(
              IN     PPROPPAGEPARAMS              pPropParams,
              IN     HWND                         hDlg
              )
/*++

Routine Description:

    Function which fills in the IDC_MAX_CONNECT control of the dialiog box with
    valid baud rates for this device.

Arguments:
    pPropParams - Context data
    hDlg - Dialog box containing IDC_MAX_CONNECT

Return Value:

    ERROR_SUCCESS or failure code

--*/
{
    LRESULT lResult;
    LONG Result = ERROR_SUCCESS;
    HKEY hKey = INVALID_HANDLE_VALUE;
    TCHAR Buf[100];
    LPTSTR CurrentMaxConnectRate = NULL;
    LPTSTR MaxConnectList = NULL;
    DWORD dwLength;
    LONG i;

    hKey = SetupDiOpenDevRegKey(pPropParams->DeviceInfoSet,
                                pPropParams->DeviceInfoData,
                                DICS_FLAG_GLOBAL,
                                0,
                                DIREG_DRV,
                                KEY_ALL_ACCESS);

    if (hKey == INVALID_HANDLE_VALUE)
    {
#if DBG
        OutputDebugString(TEXT("IrSIRCoClassInstaller:InitMaxConnect:SetupDiOpenDevRegKey failed\n"));
#endif
        Result = GetLastError();
    }
    else
    {
        LONG TmpResult;

        // Read the MaxConnectRate.  If it doesn't exist, we'll use the BaudTable instead.

        TmpResult = MyRegQueryValueEx(
                              hKey,
                              TEXT("MaxConnectList"),
                              NULL,
                              NULL,
                              (LPBYTE*)&MaxConnectList,
                              &dwLength);

        if (TmpResult == ERROR_SUCCESS)
        {
            i = 0;


            // Parse the MULTI_SZ, and add each string to IDC_MAX_CONNECT
            // We assume the values are ordered.

            while (MaxConnectList[i])
            {
                SendDlgItemMessage(hDlg,
                                   IDC_MAX_CONNECT,
                                   LB_ADDSTRING,
                                   0,
                                   (LPARAM)&MaxConnectList[i]);

                while (MaxConnectList[i]) i++;

                i++;  // advance past the null

                if ((unsigned)i>=dwLength)
                {
                    break;
                }
            }
        }
        else
        {
            // Key not found, use default baud table.

            for (i=NUM_BAUD_RATES-1; i>=0; i--)
            {
                SendDlgItemMessage(hDlg,
                                   IDC_MAX_CONNECT,
                                   LB_ADDSTRING,
                                   0,
                                   (LPARAM)BaudTable[i]);
            }
        }

        TmpResult = MyRegQueryValueEx(
                              hKey,
                              TEXT("MaxConnectRate"),
                              NULL,
                              NULL,
                              (LPBYTE*)&CurrentMaxConnectRate,
                              &dwLength);

        lResult = SendDlgItemMessage(
                               hDlg,
                               IDC_MAX_CONNECT,
                               LB_FINDSTRINGEXACT,
                               0,
                               (LPARAM)CurrentMaxConnectRate);


        if (lResult==LB_ERR)
        {
            i = 0;
            pPropParams->MaxConnectInitialValue = -1;
        }
        else
        {
            i = (LONG)lResult;
            pPropParams->MaxConnectInitialValue = i;
        }

        SendDlgItemMessage(hDlg,
                           IDC_MAX_CONNECT,
                           LB_SETCURSEL,
                           i,
                           0);
    }

    if (CurrentMaxConnectRate)
    {
        LocalFree(CurrentMaxConnectRate);
    }

    if (MaxConnectList)
    {
        LocalFree(MaxConnectList);
    }

    if (hKey!=INVALID_HANDLE_VALUE)
    {
        RegCloseKey(hKey);
    }

    return Result;
}

BOOL
EnablePortSelection(
                   IN     HDEVINFO                     DeviceInfoSet,
                   IN     PSP_DEVINFO_DATA             DeviceInfoData,
                   IN     HWND                         hDlg
                   )
/*++

Routine Description:

    This function determines whether the dialog box should have a port
    selection entry, and if so enables the appropriate controls:
    IDC_PORT_BOX, IDC_PORT_TEXT, IDC_PORT.

Arguments:

    DeviceInfoSet - As passed in to IrSIRClassCoInstaller
    DeviceInfoData - As passed in to IrSIRClassCoInstaller
    hDlg - Dialog box containing IDC_PORT and associated controls

Return Value:

    TRUE if PortSelection was enabled.

--*/
{
    LONG Result = ERROR_SUCCESS;
    HKEY hKey = INVALID_HANDLE_VALUE;
    TCHAR Buf[100];
    TCHAR SerialBased[16] = TEXT("");
    DWORD dwLength;
    LONG i;
    BOOL bSerialBased = FALSE;

    hKey = SetupDiOpenDevRegKey(DeviceInfoSet,
                                DeviceInfoData,
                                DICS_FLAG_GLOBAL,
                                0,
                                DIREG_DRV,
                                KEY_ALL_ACCESS);

    if (hKey == INVALID_HANDLE_VALUE)
    {
#if DBG
        OutputDebugString(TEXT("IrSIRCoClassInstaller:EnablePortSelection:SetupDiOpenDevRegKey failed\n"));
#endif
    }
    else
    {
        // Read the MaxConnectRate.  If it's empty, we'll start with an empty value.

        dwLength = sizeof(SerialBased);

        Result = RegQueryValueEx(hKey,
                                TEXT("SerialBased"),
                                NULL,
                                NULL,
                                (LPBYTE)SerialBased,
                                &dwLength);

        bSerialBased = (Result==ERROR_SUCCESS) ? _ttol(SerialBased) : TRUE;

        if (bSerialBased)
        {
            DWORD ControlsToShow[] = { IDC_PORT_BOX, IDC_PORT_TEXT, IDC_PORT };

            for (i=0; i<sizeof(ControlsToShow)/sizeof(ControlsToShow[0]); i++)
            {
                ShowWindow(GetDlgItem(hDlg, ControlsToShow[i]),
                           SW_SHOWNA);
            }
        }
    }

    if (hKey!=INVALID_HANDLE_VALUE)
    {
        RegCloseKey(hKey);
    }

    return bSerialBased;
}

LONG
InitDescription(
               IN     HDEVINFO                     DeviceInfoSet,
               IN     PSP_DEVINFO_DATA             DeviceInfoData,
               IN     HWND                         hDlg
               )
/*++

Routine Description:

    Function to fill the IDC_DEVICE_DESC box with an appropriate description
    of the device being configured.

Arguments:

    DeviceInfoSet - As passed in to IrSIRClassCoInstaller
    DeviceInfoData - As passed in to IrSIRClassCoInstaller
    hDlg - Dialog box containing IDC_DEVICE_DESC

Return Value:

    ERROR_SUCCESS or failure code

--*/
{
    LONG Result = ERROR_SUCCESS;
    TCHAR Description[LINE_LEN] = TEXT("Failed to retrive description");
    DWORD dwLength;

    if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
                                          DeviceInfoData,
                                          SPDRP_DEVICEDESC,
                                          NULL,
                                          (LPBYTE)Description,
                                          sizeof(Description),
                                          &dwLength))
    {
        Result = GetLastError();
#if DBG
        {
            TCHAR buf[100];
            wsprintf(buf, TEXT("IrSIRCoClassInstaller:InitDescription:SetupDiGetDeviceRegistryProperty failed (0x%08x)\n"), Result);
            OutputDebugString(buf);
        }
#endif
    }
    // Display it
    SetDlgItemText(hDlg, IDC_DEVICE_DESC, Description);

    return Result;
}

LONG
WriteRegistrySettings(
                      IN HWND             hDlg,
                      IN PPROPPAGEPARAMS  pPropParams
                     )
/*++

Routine Description:

    Function to write Port and MaxConnectRate values to the devnode key.
    This also ensures that the miniport is restarted to pick up these changes.
    It usually means someone has changed a value in the device manager.

Arguments:

    hDlg - Dialog box containing IDC_PORT and associated controls
    pPropParams - Local context data for this devnode

Return Value:

    ERROR_SUCCESS or failure code

--*/
{
    TCHAR szPort[16], szMaxConnectRate[16];
    HKEY hKey;
    LRESULT lResult;
    DWORD i;
    LONG Result = ERROR_SUCCESS;
    BOOL PropertiesChanged = FALSE;
    TCHAR buf[100];

#if DBG
    OutputDebugString(TEXT("IrSIRCoClassInstaller:WriteRegistrySettings\n"));
#endif
    //
    // Write out the com port options to the registry.  These options
    // are read by the NDIS miniport via NdisReadConfiguration()
    //
    if (pPropParams->SerialBased)
    {
        lResult = SendDlgItemMessage(hDlg,
                                     IDC_PORT,
                                     LB_GETCURSEL,
                                     0, 0);
        SendDlgItemMessage(hDlg,
                           IDC_PORT,
                           LB_GETTEXT,
                           (UINT)lResult, (LPARAM)szPort);

        if ((unsigned)lResult!=pPropParams->PortInitialValue)
        {
            PropertiesChanged = TRUE;
        }
    }

    if (pPropParams->FirstTimeInstall)
    {
        lstrcpy(szMaxConnectRate, DEFAULT_MAX_CONNECT_RATE);
    }
    else
    {
        lResult = SendDlgItemMessage(hDlg,
                               IDC_MAX_CONNECT,
                               LB_GETCURSEL,
                               0, 0);
        SendDlgItemMessage(hDlg,
                           IDC_MAX_CONNECT,
                           LB_GETTEXT,
                           (UINT)lResult, (LPARAM)szMaxConnectRate);
        if ((unsigned)lResult!=pPropParams->MaxConnectInitialValue)
        {
            PropertiesChanged = TRUE;
        }
    }

    hKey = SetupDiOpenDevRegKey(pPropParams->DeviceInfoSet,
                                pPropParams->DeviceInfoData,
                                DICS_FLAG_GLOBAL,
                                0,
                                DIREG_DRV,
                                KEY_ALL_ACCESS);

    if (hKey == INVALID_HANDLE_VALUE)
    {
#if DBG
        OutputDebugString(TEXT("IrSIRCoClassInstaller:WriteRegistrySettings:SetupDiOpenDevRegKey failed\n"));
#endif
    }
    else
    {
        if (pPropParams->SerialBased)
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -