INT_PTR CALLBACK DialogProcPropertyPageAdvancedBtnClicked(_In_ HWND hwndDlg, _In_ UINT hwndDlgItem, _Inout_ PCOISANE_Data privateData) { PWINSANE_Session oSession; PWINSANE_Device oDevice; PWINSANE_Params oParams; oSession = WINSANE_Session::Remote(privateData->lpHost, privateData->usPort); if (oSession) { if (oSession->Init(NULL, NULL) == SANE_STATUS_GOOD) { if (oSession->FetchDevices() == SANE_STATUS_GOOD) { oDevice = oSession->GetDevice(privateData->lpName); if (oDevice) { if (oDevice->Open() == SANE_STATUS_GOOD) { switch (hwndDlgItem) { case IDC_PROPERTIES_BUTTON_CHECK: if (oDevice->GetParams(&oParams) == SANE_STATUS_GOOD) { delete oParams; MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_PROPERTIES_SCANNER_CHECK_SUCCESSFUL, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONINFORMATION | MB_OK); } else { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_PROPERTIES_SCANNER_CHECK_FAILED, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONEXCLAMATION | MB_OK); } break; case IDC_PROPERTIES_BUTTON_RESET: if (oDevice->Cancel() == SANE_STATUS_GOOD) { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_PROPERTIES_SCANNER_RESET_SUCCESSFUL, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONINFORMATION | MB_OK); } else { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_PROPERTIES_SCANNER_RESET_FAILED, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONEXCLAMATION | MB_OK); } break; } oDevice->Close(); } else { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_DEVICE_OPEN_FAILED, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONEXCLAMATION | MB_OK); } } else { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_DEVICE_FIND_FAILED, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONEXCLAMATION | MB_OK); } } else { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_DEVICE_FIND_FAILED, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONEXCLAMATION | MB_OK); } oSession->Exit(); } else { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_SESSION_INIT_FAILED, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONEXCLAMATION | MB_OK); } delete oSession; } else { MessageBoxR(privateData->hHeap, privateData->hInstance, hwndDlg, IDS_SESSION_CONNECT_FAILED, IDS_PROPERTIES_SCANNER_DEVICE, MB_ICONEXCLAMATION | MB_OK); } return FALSE; }
BOOL InitPropertyPageAdvanced(_In_ HWND hwndDlg, _Inout_ PCOISANE_Data privateData) { PWINSANE_Session oSession; PWINSANE_Device oDevice; LONG index; HWND hwnd; BOOL res; QueryDeviceData(privateData); if (!privateData->lpHost) privateData->lpHost = StringAClone(privateData->hHeap, TEXT("localhost")); if (!privateData->usPort) privateData->usPort = WINSANE_DEFAULT_PORT; oSession = WINSANE_Session::Remote(privateData->lpHost, privateData->usPort); if (oSession) { if (oSession->Init(NULL, NULL) == SANE_STATUS_GOOD) { hwnd = GetDlgItem(hwndDlg, IDC_PROPERTIES_COMBO_SCANNER); if (oSession->FetchDevices() == SANE_STATUS_GOOD) { for (index = 0; index < oSession->GetDevices(); index++) { oDevice = oSession->GetDevice(index); if (oDevice) { SendMessageA(hwnd, CB_ADDSTRING, (WPARAM) 0, (LPARAM) oDevice->GetName()); } } } res = oSession->Exit() == SANE_STATUS_GOOD; } else { res = FALSE; } delete oSession; } else { res = FALSE; } if (privateData->lpName) SendDlgItemMessage(hwndDlg, IDC_PROPERTIES_COMBO_SCANNER, CB_SELECTSTRING, (WPARAM) -1, (LPARAM) privateData->lpName); if (privateData->lpUsername) SetDlgItemText(hwndDlg, IDC_PROPERTIES_EDIT_USERNAME, privateData->lpUsername); if (privateData->lpPassword) SetDlgItemText(hwndDlg, IDC_PROPERTIES_EDIT_PASSWORD, privateData->lpPassword); return res; }
BOOL ExitPropertyPageAdvanced(_In_ HWND hwndDlg, _Inout_ PCOISANE_Data privateData) { SP_DEVINSTALL_PARAMS devInstallParams; PWINSANE_Session oSession; PWINSANE_Device oDevice; LPTSTR lpName; LPTSTR lpUsername; LPTSTR lpPassword; BOOL res; lpName = (LPTSTR) HeapAlloc(privateData->hHeap, HEAP_ZERO_MEMORY, sizeof(TCHAR) * MAX_PATH); if (lpName) { res = GetDlgItemText(hwndDlg, IDC_PROPERTIES_COMBO_SCANNER, lpName, MAX_PATH); if (res) { if (privateData->lpName) { HeapFree(privateData->hHeap, 0, privateData->lpName); } privateData->lpName = lpName; } else { HeapFree(privateData->hHeap, 0, lpName); } } else { res = FALSE; } if (res) { lpUsername = (LPTSTR) HeapAlloc(privateData->hHeap, HEAP_ZERO_MEMORY, sizeof(TCHAR) * MAX_PATH); if (lpUsername) { if (GetDlgItemText(hwndDlg, IDC_PROPERTIES_EDIT_USERNAME, lpUsername, MAX_PATH)) { if (privateData->lpUsername) { HeapFree(privateData->hHeap, 0, privateData->lpUsername); } privateData->lpUsername = lpUsername; } else { HeapFree(privateData->hHeap, 0, lpUsername); } } lpPassword = (LPTSTR) HeapAlloc(privateData->hHeap, HEAP_ZERO_MEMORY, sizeof(TCHAR) * MAX_PATH); if (lpPassword) { if (GetDlgItemText(hwndDlg, IDC_PROPERTIES_EDIT_PASSWORD, lpPassword, MAX_PATH)) { if (privateData->lpPassword) { HeapFree(privateData->hHeap, 0, privateData->lpPassword); } privateData->lpPassword = lpPassword; } else { HeapFree(privateData->hHeap, 0, lpPassword); } } oSession = WINSANE_Session::Remote(privateData->lpHost, privateData->usPort); if (oSession) { if (oSession->Init(NULL, NULL) == SANE_STATUS_GOOD) { if (oSession->FetchDevices() == SANE_STATUS_GOOD) { oDevice = oSession->GetDevice(privateData->lpName); if (oDevice) { UpdateDeviceInfo(privateData, oDevice); UpdateDeviceData(privateData, oDevice); ZeroMemory(&devInstallParams, sizeof(SP_DEVINSTALL_PARAMS)); devInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS); res = SetupDiGetDeviceInstallParams(privateData->hDeviceInfoSet, privateData->pDeviceInfoData, &devInstallParams); if (res) { devInstallParams.FlagsEx |= DI_FLAGSEX_PROPCHANGE_PENDING; res = SetupDiSetDeviceInstallParams(privateData->hDeviceInfoSet, privateData->pDeviceInfoData, &devInstallParams); } } else { res = FALSE; } } else { res = FALSE; } if (oSession->Exit() != SANE_STATUS_GOOD) { res = FALSE; } } else { res = FALSE; } delete oSession; } else { res = FALSE; } } return res; }