summaryrefslogtreecommitdiff
path: root/general/toaster/toastpkg/toastva/wizard.c
blob: 5f876a3f13cba106722848030e235162a26e770b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
/*++

Copyright (c) Microsoft Corporation.  All rights reserved.

    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
    KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
    PURPOSE.

Module Name:

    wizard.c

Abstract:

    This module implements the TOASTVA wizard that installs/updates toaster
    drivers and allows the user to select additional value-added software.

--*/

#include "precomp.h"
#pragma hdrstop

//
// Constants
//
#define WMX_UPDATE_DRIVER_DONE (WM_USER + 500)

//
// Structures
//
typedef struct _SHAREDWIZDATA {
    HFONT   hTitleFont;          // Title font for the Welcome and Completion pages
    BOOL    HwInsertedFirst;     // Is the hardware already present?
    LPCWSTR MediaRootDirectory;  // Fully-qualified path to root of install media
    BOOL    DoDriverUpdatePage;  // Should Update Driver page do anything?
    BOOL    RebootRequired;      // Did we do anything that requires a reboot?
    HWND    hwndDlg;             // Handle to dialog notified by drv update thread
} SHAREDWIZDATA, *LPSHAREDWIZDATA;

//
// Function prototypes
//
INT_PTR
CALLBACK
IntroDlgProc(
    _In_ HWND     hwndDlg,
    _In_ UINT     uMsg,
    _In_ WPARAM   wParam,
    _In_ LPARAM   lParam
    );

INT_PTR
CALLBACK
IntPage1DlgProc(
    _In_ HWND     hwndDlg,
    _In_ UINT     uMsg,
    _In_ WPARAM   wParam,
    _In_ LPARAM   lParam
    );

INT_PTR
CALLBACK
EndDlgProc(
    _In_ HWND     hwndDlg,
    _In_ UINT     uMsg,
    _In_ WPARAM   wParam,
    _In_ LPARAM   lParam
    );

DWORD
WINAPI
UpdateDriverThreadProc(
    _In_ LPVOID ThreadData
    );

INT
CALLBACK
WizardCallback(
    _In_ HWND   hwndDlg,
    _In_ UINT   uMsg,
    _In_ LPARAM lParam
    );

//
// Prototype for a routine exported from toastco.dll
//
HPROPSHEETPAGE
GetValueAddSoftwareWizPage(
    _In_ LPCWSTR MediaRootDirectory,
    _In_opt_ LPCWSTR MediaDiskName,
    _In_opt_ LPCWSTR MediaTagFile
    );

//
// Implementation
//

VOID
DoValueAddWizard(
    _In_ LPCWSTR MediaRootDirectory
    )

/*++

Routine Description:

    This routine displays a wizard that steps the user through the following
    actions:

    (a) Performs a "driver update" for any currently-present toasters
    (b) Installs the INF and CAT in case no toasters presently exist
    (c) Optionally, installs value-add software selected by the user (this
        wizard page is retrieved from the toaster co-installer, and is the same
        page the user gets if they do a "hardware-first" installation using our
        driver).

Arguments:

    MediaRootDirectory - Supplies the fully-qualified path to the root
        directory where the installation media is located.

Return Value:

    none

--*/

{
    PROPSHEETPAGE   psp =       {0}; //defines the property sheet pages
    HPROPSHEETPAGE  ahpsp[4] =  {0}; //an array to hold the page's HPROPSHEETPAGE handles
    PROPSHEETHEADER psh =       {0}; //defines the property sheet
    SHAREDWIZDATA wizdata =     {0}; //the shared data structure

    NONCLIENTMETRICS ncm = {0};
    LOGFONT TitleLogFont;
    HDC hdc;
    INT FontSize;
    INT index = 0;
    HRESULT hr;

    //
    //Create the Wizard pages
    //
    // Intro page...
    //
    psp.dwSize =        sizeof(psp);
    psp.dwFlags =       PSP_DEFAULT|PSP_HIDEHEADER;
    psp.hInstance =     g_hInstance;
    psp.lParam =        (LPARAM) &wizdata; //The shared data structure
    psp.pfnDlgProc =    IntroDlgProc;
    psp.pszTemplate =   MAKEINTRESOURCE(IDD_INTRO);

    ahpsp[index++] =          CreatePropertySheetPage(&psp);

    //
    // Updating drivers page...
    //
    psp.dwFlags =           PSP_DEFAULT|PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE|PSP_USETITLE;
    psp.pszHeaderTitle =    MAKEINTRESOURCE(IDS_TITLE1);
    psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE1);
    psp.pszTemplate =       MAKEINTRESOURCE(IDD_INTERIOR1);
    psp.pfnDlgProc =        IntPage1DlgProc;

    ahpsp[index++] =              CreatePropertySheetPage(&psp);

    //
    // Retrieve the value-add software chooser page from the toaster
    // co-installer (toastco.dll).
    //
    ahpsp[index] = GetValueAddSoftwareWizPage(MediaRootDirectory, NULL, NULL);

    if(ahpsp[index]) {
        index++;
    }

    //
    // Finish page...
    //
    psp.dwFlags =       PSP_DEFAULT|PSP_HIDEHEADER;
    psp.pszTemplate =   MAKEINTRESOURCE(IDD_END);
    psp.pfnDlgProc =    EndDlgProc;

    ahpsp[index] =          CreatePropertySheetPage(&psp);

    //
    // Create the property sheet...
    //
    psh.dwSize =            sizeof(psh);
    psh.hInstance =         g_hInstance;
    psh.hwndParent =        NULL;
    psh.phpage =            ahpsp;
    psh.dwFlags =           PSH_WIZARD97|PSH_WATERMARK|PSH_HEADER|PSH_STRETCHWATERMARK|PSH_WIZARD|PSH_USECALLBACK;
    psh.pszbmWatermark =    MAKEINTRESOURCE(IDB_WATERMARK);
    psh.pszbmHeader =       MAKEINTRESOURCE(IDB_BANNER);
    psh.nStartPage =        0;
    psh.nPages =            4;
    psh.pfnCallback =       WizardCallback;

    //
    // Set up the font for the titles on the intro and ending pages
    //
    ncm.cbSize = sizeof(ncm);
    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);

    //
    // Create the intro/end title font
    //
    TitleLogFont = ncm.lfMessageFont;
    TitleLogFont.lfWeight = FW_BOLD;
    hr = StringCchCopy(TitleLogFont.lfFaceName, LF_FACESIZE, L"Verdana Bold");
    if(SUCCEEDED(hr) == FALSE) {
        return; // assert
    }

    hdc = GetDC(NULL); //gets the screen DC
    FontSize = 12;
    TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72;
    wizdata.hTitleFont = CreateFontIndirect(&TitleLogFont);
    ReleaseDC(NULL, hdc);
    wizdata.MediaRootDirectory = MediaRootDirectory;

    //
    // Display the wizard
    //
    PropertySheet(&psh);

    //
    // Destroy the fonts
    //
    DeleteObject(wizdata.hTitleFont);

    //
    // If we did anything that requires a reboot, prompt the user
    // now.  Note that we need to do this regardle
    //
    if(wizdata.RebootRequired) {
        SetupPromptReboot(NULL, NULL, FALSE);
    }
}


INT_PTR
CALLBACK
IntroDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )

/*++

Routine Description:

    This function is the dialog procedure for the Welcome page of the wizard.

Arguments:

    hwndDlg - Supplies a handle to the dialog box window

    uMsg - Supplies the message

    wParam - Supplies the first message parameter

    lParam - Supplies the second message parameter

Return Value:

    This dialog procedure always returns zero.

--*/

{
    LPSHAREDWIZDATA pdata;
    LPNMHDR lpnm;

    UNREFERENCED_PARAMETER( wParam );

    //
    // Retrieve the shared user data from GWL_USERDATA
    //
    pdata = (LPSHAREDWIZDATA) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

    switch(uMsg) {

        case WM_INITDIALOG :
            {
                HWND hwndControl;

                //
                // Get the shared data from PROPSHEETPAGE lParam valueand load
                // it into GWL_USERDATA
                //
                pdata = (LPSHAREDWIZDATA) ((LPPROPSHEETPAGE) lParam) -> lParam;

                SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) pdata);

                //
                // It's an intro/end page, so get the title font from the
                // shared data and use it for the title control
                //
                hwndControl = GetDlgItem(hwndDlg, IDC_TITLE);
                SetWindowFont(hwndControl,pdata->hTitleFont, TRUE);
                break;
            }

        case WM_NOTIFY :

            lpnm = (LPNMHDR)lParam;

            switch(lpnm->code) {

                case PSN_SETACTIVE :
                    //
                    // Enable the Next button
                    //
                    PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);

                    //
                    // When we're moving forward through the wizard, we want
                    // the driver update page to do its work.
                    //
                    pdata->DoDriverUpdatePage = TRUE;
                    break;

                case PSN_WIZNEXT :
                    //Handle a Next button click here
                    break;

                case PSN_RESET :
                    //Handle a Cancel button click, if necessary
                    break;

                default :
                    break;
            }
            break;

        default:
            break;
    }

    return 0;
}


INT_PTR
CALLBACK
IntPage1DlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )

/*++

Routine Description:

    This function is the dialog procedure for the first interior wizard page.
    This page updates the drivers for any existing (present) devices, or
    installs the INF if there aren't any present devices.

Arguments:

    hwndDlg - Supplies a handle to the dialog box window

    uMsg - Supplies the message

    wParam - Supplies the first message parameter

    lParam - Supplies the second message parameter

Return Value:

    This dialog procedure always returns zero.

--*/

{
    LPSHAREDWIZDATA pdata;
    LPNMHDR lpnm;
    HANDLE hThread;
    HKEY hKey;
    DWORD UserPrompted;

    UNREFERENCED_PARAMETER( wParam );

    //
    // Retrieve the shared user data from GWL_USERDATA
    //
    pdata = (LPSHAREDWIZDATA) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

    switch(uMsg) {

        case WM_INITDIALOG :
            //
            // Get the PROPSHEETPAGE lParam value and load it into GWL_USERDATA
            //
            pdata = (LPSHAREDWIZDATA) ((LPPROPSHEETPAGE) lParam) -> lParam;
            SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) pdata);
            break;

        case WM_NOTIFY :

            lpnm = (LPNMHDR)lParam;

            switch(lpnm->code) {

                case PSN_SETACTIVE :
                    //
                    // If we're coming here from the intro page, then disable
                    // the Back and Next buttons (we're going to be busy for a
                    // little bit updating drivers).
                    //
                    // If we're coming to this page from anywhere else,
                    // immediately jump to the intro page.
                    //
                    if(pdata->DoDriverUpdatePage) {
                        //
                        // Reset our flag so that we won't try this again if we
                        // go to later pages, then come back to this one.  (We
                        // only do anything when the wizard page is accessed in
                        // the forward direction, from the Intro page.)
                        //
                        pdata->DoDriverUpdatePage = FALSE;

                        //
                        // Set our "UserPrompted" registry flag so the
                        // co-installer won't popup its own value-add software
                        // chooser page during driver update.
                        //
                        if(ERROR_SUCCESS == RegCreateKeyEx(
                                                HKEY_LOCAL_MACHINE,
                                                TEXT("SOFTWARE\\Microsoft\\Toaster"),
                                                0,
                                                NULL,
                                                REG_OPTION_NON_VOLATILE,
                                                KEY_READ | KEY_WRITE,
                                                NULL,
                                                &hKey,
                                                NULL)) {

                            UserPrompted = 1;
                            RegSetValueEx(hKey,
                                          TEXT("User Prompted"),
                                          0,
                                          REG_DWORD,
                                          (PBYTE)&UserPrompted,
                                          sizeof(UserPrompted)
                                         );

                            RegCloseKey(hKey);
                        }

                        //
                        // Disable Next, Back, and Cancel
                        //
                        PropSheet_SetWizButtons(GetParent(hwndDlg), 0);
                        EnableWindow(GetDlgItem(GetParent(hwndDlg), IDCANCEL), FALSE);

                        //
                        // Show "searching" animation...
                        //
                        ShowWindow(GetDlgItem(hwndDlg, IDC_ANIMATE1), SW_SHOW);
                        Animate_Open(GetDlgItem(hwndDlg, IDC_ANIMATE1), MAKEINTRESOURCE(IDA_SEARCHING));
                        Animate_Play(GetDlgItem(hwndDlg, IDC_ANIMATE1), 0, -1, -1);

                        //
                        // Create a thread to do the work of updating the
                        // driver, etc.
                        //
                        pdata->hwndDlg = hwndDlg;

                        hThread = CreateThread(NULL,
                                               0,
                                               UpdateDriverThreadProc,
                                               pdata,
                                               0,
                                               NULL
                                              );

                        if(hThread) {
                            //
                            // Thread launched successfully--close the handle,
                            // then just wait to be notified of thread's
                            // completion.
                            //
                            CloseHandle(hThread);

                        } else {
                            //
                            // Couldn't launch the thread--just move on to the
                            // value-add software page.
                            //
                            PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
                            PropSheet_PressButton(GetParent(hwndDlg), PSBTN_NEXT);
                        }

                    } else {
                        //
                        // We're coming "back" to this page.  Skip it, and go
                        // to the intro page.
                        //
                        PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
                        PropSheet_PressButton(GetParent(hwndDlg), PSBTN_BACK);
                    }
                    break;

                case PSN_WIZNEXT :
                    //Handle a Next button click, if necessary
                    break;

                case PSN_WIZBACK :
                    //Handle a Back button click, if necessary
                    break;

                case PSN_RESET :
                    //Handle a Cancel button click, if necessary
                    break;

                default :
                    break;
            }
            break;

        case WMX_UPDATE_DRIVER_DONE :
            //
            // Stop "searching" animation...
            //
            Animate_Stop(GetDlgItem(hwndDlg, IDC_ANIMATE1));
            ShowWindow(GetDlgItem(hwndDlg, IDC_ANIMATE1), SW_HIDE);

            //
            // Regardless of whether we succeeded in upgrading any drivers, we'll
            // go ahead and proceed to the value-add software page.
            //
            PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
            EnableWindow(GetDlgItem(GetParent(hwndDlg), IDCANCEL), TRUE);

            PropSheet_PressButton(GetParent(hwndDlg), PSBTN_NEXT);

            break;

        default:
            break;
    }

    return 0;
}


INT_PTR
CALLBACK
EndDlgProc(
    _In_ HWND hwndDlg,
    _In_ UINT uMsg,
    _In_ WPARAM wParam,
    _In_ LPARAM lParam
    )

/*++

Routine Description:

    This function is the dialog procedure for the Finish page of the wizard.

Arguments:

    hwndDlg - Supplies a handle to the dialog box window

    uMsg - Supplies the message

    wParam - Supplies the first message parameter

    lParam - Supplies the second message parameter

Return Value:

    This dialog procedure always returns zero.

--*/

{
    LPSHAREDWIZDATA pdata;
    LPNMHDR lpnm;

    UNREFERENCED_PARAMETER( wParam );

    //
    // Retrieve the shared user data from GWL_USERDATA
    //
    pdata = (LPSHAREDWIZDATA) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

    switch(uMsg) {

        case WM_INITDIALOG :
            {
                HWND hwndControl;

                //
                // Get the shared data from PROPSHEETPAGE lParam value and load
                // it into GWL_USERDATA
                //
                pdata = (LPSHAREDWIZDATA) ((LPPROPSHEETPAGE) lParam) -> lParam;
                SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) pdata);

                //
                // It's an intro/end page, so get the title font from userdata
                // and use it on the title control
                //
                hwndControl = GetDlgItem(hwndDlg, IDC_TITLE);
                SetWindowFont(hwndControl,pdata->hTitleFont, TRUE);
                break;
            }

        case WM_NOTIFY :

            lpnm = (LPNMHDR)lParam;

            switch(lpnm->code) {

                case PSN_SETACTIVE :
                    //
                    // Enable the correct buttons for the active page
                    //
                    PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);

                    //
                    // Doesn't make sense to have Cancel button enabled here
                    //
                    EnableWindow(GetDlgItem(GetParent(hwndDlg),  IDCANCEL), FALSE);

                    //
                    // If we didn't find any currently-present devices, then prompt
                    // the user to insert their device now.
                    //
                    if(!pdata->HwInsertedFirst) {

                        WCHAR TempString[LINE_LEN];

                        if(LoadString(g_hInstance,
                                      IDS_PROMPT_FOR_HW,
                                      TempString,
                                      sizeof(TempString) / sizeof(WCHAR))) {

                            SetDlgItemText(hwndDlg, IDC_FINISH_TEXT, TempString);
                        }
                    }

                    break;

                case PSN_WIZBACK :
                    //
                    // Jumping back from this page, so turn Cancel button back on.
                    //
                    EnableWindow(GetDlgItem(GetParent(hwndDlg),  IDCANCEL), TRUE);
                    break;

                default :
                    break;
            }
            break;

        default:
            break;
    }

    return 0;
}


DWORD
WINAPI
UpdateDriverThreadProc(
    _In_ LPVOID ThreadData
    )

/*++

Routine Description:

    This function updates the drivers for any existing toasters.  If there are
    no toasters currently connected to the computer, it installs the INF/CAT so
    that the system will be ready to automatically install toasters that are
    plugged in later.  This routine will also mark any non-present (aka,
    "phantom") toasters as needs-reinstall, so that they'll be updated to the
    new driver if they're ever plugged in again.

Arguments:

    ThreadData - Supplies a pointer to a SHAREDWIZDATA structure that's used
        both by this thread, and by the wizard in the main thread.

Return Value:

    If successful, the function returns NO_ERROR.

    Otherwise, the function returns a Win32 error code indicating the cause of
    failure.

--*/

{
    DWORD Err;
    LPSHAREDWIZDATA pdata;
    WCHAR FullInfPath[MAX_PATH];
    HDEVINFO ExistingNonPresentDevices;


    pdata = (LPSHAREDWIZDATA)ThreadData;
    Err = NO_ERROR;

    //
    // First, attempt to update any present devices to our driver...
    //
    if (FAILED(StringCchCopy(FullInfPath, MAX_PATH, pdata->MediaRootDirectory))) {
        return ERROR_NOT_ENOUGH_MEMORY;
    }

    if (FAILED(StringCchCat(FullInfPath, MAX_PATH, DEVICE_INF_NAME))) {
        return ERROR_NOT_ENOUGH_MEMORY;
    }

    if(UpdateDriverForPlugAndPlayDevices(GetParent(pdata->hwndDlg),
                                         HW_ID_TO_UPDATE,
                                         FullInfPath,
                                         0,
                                         &pdata->RebootRequired)) {
        //
        // We know that at least one device existed, and was upgraded.
        //
        pdata->HwInsertedFirst = TRUE;

    } else {

        Err = GetLastError();

        //
        // We failed to update the driver.  If we failed simply because
        // there were no toasters currently attached to the computer, then
        // we still want to install the INF.
        //
        if(Err == ERROR_NO_SUCH_DEVINST) {

            pdata->HwInsertedFirst = FALSE;

            //
            // Since we didn't do any device installs, the INF (and CAT)
            // didn't get automatically installed.  We'll install them now,
            // so that they'll be present when the user subsequently plugs
            // their hardware in.
            //
            if(!SetupCopyOEMInf(FullInfPath,
                                NULL,
                                SPOST_PATH,
                                0,
                                NULL,
                                0,
                                NULL,
                                NULL)) {
                //
                // Failure to install the INF is more important (worse) than
                // the absence of any devices!
                //
                Err = GetLastError();
            }

        } else {
            //
            // Apparently there _were_ existing devices--we just failed to
            // upgrade their drivers.  This might be due to an installation
            // problem, or perhaps because the devices already have drivers
            // newer than the one we offered.
            //
            pdata->HwInsertedFirst = TRUE;
        }
    }

    if((Err == NO_ERROR) || (Err == ERROR_NO_SUCH_DEVINST)) {
        //
        // Either we successfully upgraded one or more toasters, or there were
        // no present toasters but we successfully installed our INF and CAT.
        //
        // There may exist, however, devices that were once connected to the
        // computer, but presently are not.  If such devices are connected
        // again in the future, we want to ensure they go through device
        // installation.  We will retrieve the list of non-present devices, and
        // mark each as "needs re-install" to kick them back through the "New
        // Hardware Found" process if they ever show up again.  (Note that this
        // doesn't destroy any device-specific settings they may have, so this
        // is just forcing an upgrade, not an uninstall/re-install.)
        //
        // (The HardwareID used is the one defined for the toaster sample,
        // BUS_HARDWARE_IDS in src\general\toaster\bus\common.h.  We also take
        // advantage of the fact that we know these devices will always be
        // enumerated under the "{b85b7c50-6a01-11d2-b841-00c04fad5171}"
        // enum namespace.)
        //
        ExistingNonPresentDevices = GetNonPresentDevices(ENUMERATOR_NAME,
                                                         HW_ID_TO_UPDATE
                                                        );

        if(ExistingNonPresentDevices != INVALID_HANDLE_VALUE) {

            MarkDevicesAsNeedReinstall(ExistingNonPresentDevices);

            SetupDiDestroyDeviceInfoList(ExistingNonPresentDevices);
        }
    }

    PostMessage(pdata->hwndDlg, WMX_UPDATE_DRIVER_DONE, 0, 0);

    return Err;
}


INT
CALLBACK
WizardCallback(
    _In_ HWND   hwndDlg,
    _In_ UINT   uMsg,
    _In_ LPARAM lParam
    )

/*++

Routine Description:

    Call back used to remove the "X" and  "?" from the wizard page.

Arguments:

    hwndDlg - Handle to the property sheet dialog box.

    uMsg - Identifies the message being received. This parameter is one of the
        following values:

        PSCB_INITIALIZED - Indicates that the property sheet is being
                           initialized. The lParam value is zero for this
                           message.

        PSCB_PRECREATE   - Indicates that the property sheet is about to be
                           created. The hwndDlg parameter is NULL and the
                           lParam parameter is a pointer to a dialog template
                           in memory. This template is in the form of a
                           DLGTEMPLATE structure followed by one or more
                           DLGITEMTEMPLATE structures.

    lParam - Specifies additional information about the message. The
        meaning of this value depends on the uMsg parameter.

Return Value:

    The function returns zero.

--*/

{
    DLGTEMPLATE *pDlgTemplate;

    UNREFERENCED_PARAMETER( hwndDlg );

    switch(uMsg) {

        case PSCB_PRECREATE:
            if(lParam){
                //
                // This is done to hide the X and ? at the top of the wizard
                //
                pDlgTemplate = (DLGTEMPLATE *)lParam;
                pDlgTemplate->style &= ~(DS_CONTEXTHELP | WS_SYSMENU);
            }
            break;

        default:
            break;
    }

    return 0;
}