📄 irclass.c
字号:
TCHAR szLocation[128], *pszLocationFmt;
Result = RegSetValueEx(hKey,
TEXT("Port"),
0,
REG_SZ,
(LPBYTE)szPort,
lstrlen(szPort)*sizeof(szPort[0]));
if(MyLoadString(ghDllInst, IDS_LOCATION_FORMAT, &pszLocationFmt))
{
wsprintf(szLocation, pszLocationFmt, szPort);
LocalFree(pszLocationFmt);
}
else
{
szLocation[0] = 0;
}
SetupDiSetDeviceRegistryProperty(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
SPDRP_LOCATION_INFORMATION,
(LPBYTE)szLocation,
(lstrlen(szLocation)+1)*sizeof(TCHAR));
}
if (Result==ERROR_SUCCESS)
{
Result = RegSetValueEx(hKey,
TEXT("MaxConnectRate"),
0,
REG_SZ,
(LPBYTE)szMaxConnectRate,
lstrlen(szMaxConnectRate)*sizeof(szMaxConnectRate[0]));
}
RegCloseKey(hKey);
}
if (Result==ERROR_SUCCESS && PropertiesChanged)
{
if (pPropParams->FirstTimeInstall)
{
// On a first time install, NT may not look for the PROPCHANGE_PENDING bit.
// Instead we will notify that the driver needs to be restarted ourselves,
// so that the changes we're writing get picked up.
SP_DEVINSTALL_PARAMS DevInstallParams;
SP_PROPCHANGE_PARAMS PropChangeParams;
ZeroMemory(&PropChangeParams, sizeof(SP_PROPCHANGE_PARAMS));
PropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChangeParams.StateChange = DICS_PROPCHANGE;
PropChangeParams.Scope = DICS_FLAG_GLOBAL;
if (SetupDiSetClassInstallParams(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
(PSP_CLASSINSTALL_HEADER)&PropChangeParams,
sizeof(SP_PROPCHANGE_PARAMS))
)
{
DevInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
if(SetupDiGetDeviceInstallParams(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
&DevInstallParams))
{
DevInstallParams.Flags |= DI_CLASSINSTALLPARAMS;
SetupDiSetDeviceInstallParams(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
&DevInstallParams);
}
else
{
#if DBG
OutputDebugString(TEXT("IrSIRCoClassInstaller:WriteRegistrySettings:SetupDiGetDeviceInstallParams failed 1\n"));
#endif
}
SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,
pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData);
if(SetupDiGetDeviceInstallParams(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
&DevInstallParams))
{
DevInstallParams.Flags |= DI_PROPERTIES_CHANGE;
SetupDiSetDeviceInstallParams(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
&DevInstallParams);
}
else
{
#if DBG
OutputDebugString(TEXT("IrSIRCoClassInstaller:WriteRegistrySettings:SetupDiGetDeviceInstallParams failed 2\n"));
#endif
}
}
else
{
#if DBG
OutputDebugString(TEXT("IrSIRCoClassInstaller:WriteRegistrySettings:SetupDiSetClassInstallParams failed \n"));
#endif
}
}
else
{
// This is the case where the user has changed settings in the property
// sheet. Life is much easier.
SP_DEVINSTALL_PARAMS DevInstallParams;
//
// The changes are written, notify the world to reset the driver.
//
DevInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
if(SetupDiGetDeviceInstallParams(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
&DevInstallParams))
{
LONG ChangeResult;
DevInstallParams.FlagsEx |= DI_FLAGSEX_PROPCHANGE_PENDING;
ChangeResult =
SetupDiSetDeviceInstallParams(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
&DevInstallParams);
#if DBG
{
wsprintf(buf, TEXT("SetupDiSetDeviceInstallParams(DI_FLAGSEX_PROPCHANGE_PENDING)==%d %x\n"), ChangeResult, GetLastError());
OutputDebugString(buf);
}
#endif
}
else
{
#if DBG
OutputDebugString(TEXT("IrSIRCoClassInstaller:WriteRegistrySettings:SetupDiGetDeviceInstallParams failed 2\n"));
#endif
}
}
}
#if DBG
{
wsprintf(buf, TEXT("IrSIRCoClassInstaller:Result==%x FirstTimeInstall==%d Changed==%d\n"),
Result, pPropParams->FirstTimeInstall, PropertiesChanged);
OutputDebugString(buf);
}
#endif
return Result;
}
INT_PTR APIENTRY PortDlgProc(IN HWND hDlg,
IN UINT uMessage,
IN WPARAM wParam,
IN LPARAM lParam)
/*++
Routine Description:
The windows control function for the IrDA Settings properties window
Arguments:
hDlg, uMessage, wParam, lParam: standard windows DlgProc parameters
Return Value:
BOOL: FALSE if function fails, TRUE if function passes
--*/
{
ULONG i;
TCHAR CharBuffer[LINE_LEN];
PPROPPAGEPARAMS pPropParams;
TCHAR buf[100];
pPropParams = (PPROPPAGEPARAMS)GetWindowLongPtr(hDlg, DWLP_USER);
switch (uMessage)
{
case WM_INITDIALOG:
//
// lParam points to one of two possible objects. If we're a property
// page, it points to the PropSheetPage structure. If we're a regular
// dialog box, it points to the PROPPAGEPARAMS structure. We can
// verify which because the first field of PROPPAGEPARAMS is a signature.
//
// In either case, once we figure out which, we store the value into
// DWL_USER so we only have to do this once.
//
pPropParams = (PPROPPAGEPARAMS)lParam;
if (pPropParams->Signature!=PPParamsSignature)
{
pPropParams = (PPROPPAGEPARAMS)((LPPROPSHEETPAGE)lParam)->lParam;
if (pPropParams->Signature!=PPParamsSignature)
{
#if DBG
OutputDebugString(TEXT("IRCLASS.DLL: PortDlgProc Signature not found!\n"));
#endif
return FALSE;
}
}
SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM)pPropParams);
if (!pPropParams->FirstTimeInstall)
{
InitMaxConnect(pPropParams, hDlg);
pPropParams->SerialBased = EnablePortSelection(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
hDlg);
if (pPropParams->SerialBased)
{
EnumSerialDevices(pPropParams, hDlg, &i);
}
InitDescription(pPropParams->DeviceInfoSet,
pPropParams->DeviceInfoData,
hDlg);
}
else
{
pPropParams->SerialBased = TRUE;
EnumSerialDevices(pPropParams, hDlg, &i);
// Enable next and cancel wizard buttons. BACK is not valid here,
// since the device is already installed at this point. Cancel
// will cause the device to be removed.
PropSheet_SetWizButtons(GetParent(hDlg), PSWIZB_NEXT);
EnableWindow(GetDlgItem(GetParent(hDlg), IDCANCEL), TRUE);
}
return TRUE; // No need for us to set the focus.
case WM_COMMAND:
switch (HIWORD(wParam))
{
case LBN_SELCHANGE:
{
#if DBG
OutputDebugString(TEXT("IrSIRCoClassInstaller:PropertySheet Changed\n"));
#endif
PropSheet_Changed(GetParent(hDlg), hDlg);
}
return TRUE;
default:
break;
}
switch (LOWORD(wParam))
{
//
// Because this is a prop sheet, we should never get this.
// All notifications for ctrols outside of the sheet come through
// WM_NOTIFY
//
case IDCANCEL:
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
EndDialog(hDlg, uMessage);
return TRUE;
case IDOK:
{
WriteRegistrySettings(hDlg, pPropParams);
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
EndDialog(hDlg, uMessage);
return TRUE;
}
default:
return FALSE;
}
case WM_NOTIFY:
switch (((NMHDR *)lParam)->code)
{
//
// Sent when the user clicks on Apply OR OK !!
//
case PSN_WIZNEXT:
if (!pPropParams->FirstTimeInstall)
{
break;
}
case PSN_APPLY:
{
WriteRegistrySettings(hDlg, pPropParams);
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
return TRUE;
}
default:
return FALSE;
}
case WM_DESTROY:
//
// free the description of the com ports. If any msgs are processed
// after WM_DESTROY, do not reference pPropParams!!! To enforce this,
// set the DWL_USER stored long to 0
//
LocalFree(pPropParams);
SetWindowLongPtr(hDlg, DWLP_USER, 0);
case WM_HELP:
if (lParam)
{
return WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle,
(LPCTSTR)szHelpFile,
HELP_WM_HELP,
(ULONG_PTR)HelpIDs);
}
else
{
return FALSE;
}
case WM_CONTEXTMENU:
return WinHelp((HWND)wParam,
(LPCTSTR)szHelpFile,
HELP_CONTEXTMENU,
(ULONG_PTR)HelpIDs);
default:
return FALSE;
}
} /* PortDialogProc */
void PortSelectionDlg(
HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData
)
/*++
Routine Description:
PropSheet setup for devnode configuration.
Arguments:
DeviceInfoSet - As passed in to IrSIRClassCoInstaller
DeviceInfoData - As passed in to IrSIRClassCoInstaller
Return Value:
--*/
{
HKEY hKey = 0;
PPROPPAGEPARAMS pPropParams = NULL;
PROPSHEETHEADER PropHeader;
PROPSHEETPAGE PropSheetPage;
TCHAR buf[100];
SP_NEWDEVICEWIZARD_DATA WizData;
WizData.ClassInstallHeader.cbSize = sizeof(WizData.ClassInstallHeader);
if (!SetupDiGetClassInstallParams(DeviceInfoSet,
DeviceInfoData,
(PSP_CLASSINSTALL_HEADER)&WizData,
sizeof(WizData),
NULL)
|| WizData.ClassInstallHeader.InstallFunction!=DIF_NEWDEVICEWIZARD_FINISHINSTALL)
{
#if DBG
OutputDebugString(TEXT("IrSIRCoClassInstaller: Failed to get ClassInstall params\n"));
#endif
return;
}
#if DBG
OutputDebugString(TEXT("IrSIRCoClassInstaller: PortSelectionDlg\n"));
#endif
pPropParams = LocalAlloc(LMEM_FIXED, sizeof(PROPPAGEPARAMS));
if (!pPropParams)
{
return;
}
pPropParams->Signature = PPParamsSignature;
pPropParams->DeviceInfoSet = DeviceInfoSet;
pPropParams->DeviceInfoData = DeviceInfoData;
pPropParams->FirstTimeInstall = TRUE;
if (WizData.NumDynamicPages < MAX_INSTALLWIZARD_DYNAPAGES)
{
//
// Setup the advanced properties window information
//
BOOLEAN bResult;
DWORD RequiredSize = 0;
DWORD dwTotalSize = 0;
LONG lResult;
memset(&PropSheetPage, 0, sizeof(PropSheetPage));
//
// Add the Port Settings property page
//
PropSheetPage.dwSize = sizeof(PROPSHEETPAGE);
PropSheetPage.dwFlags = PSP_DEFAULT; //PSP_USECALLBACK; // | PSP_HASHELP;
PropSheetPage.hInstance = ghDllInst;
PropSheetPage.pszTemplate = MAKEINTRESOURCE(IDD_INSTALL_PORT_SELECT);
//
// following points to the dlg window proc
//
PropSheetPage.hIcon = NULL;
PropSheetPage.pfnDlgProc = PortDlgProc;
PropSheetPage.lParam = (LPARAM)pPropParams;
//
// following points to some control callback of the dlg window proc
//
PropSheetPage.pfnCallback = NULL;
PropSheetPage.pcRefParent = NULL;
#if 0
// We don't use these, but if we wanted to...
PropSheetPage.dwFlags |= PSP_USEHEADERTITLE;
PropSheetPage.pszHeaderTitle = TEXT("Header Title");
PropSheetPage.dwFlags |= PSP_USEHEADERSUBTITLE;
PropSheetPage.pszHeaderTitle = TEXT("Header Subtitle");
#endif
WizData.DynamicPages[WizData.NumDynamicPages] = CreatePropertySheetPage(&PropSheetPage);
if (WizData.DynamicPages[WizData.NumDynamicPages])
{
WizData.NumDynamicPages++;
}
SetupDiSetClassInstallParams(DeviceInfoSet,
DeviceInfoData,
(PSP_CLASSINSTALL_HEADER)&WizData,
sizeof(WizData));
}
else
{
LocalFree(pPropParams);
}
} /* PortSelectionDlg */
VOID
DestroyPrivateData(PCOINSTALLER_PRIVATE_DATA pPrivateData)
/*++
Routine Description:
Function to dealloc/destroy context data
Arguments:
pPrivateData - Context buffer to dealloc/destroy
Return Value:
none
--*/
{
if (pPrivateData)
{
if (pPrivateData->hInf!=INVALID_HANDLE_VALUE)
{
SetupCloseInfFile(pPrivateData->hInf);
}
LocalFree(pPrivateData);
pPrivateData = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -