Installation

zhaozj2021-02-16  69

When I use the VC to drive the installer, install the call is the DDK's install program. When using it, it can be installed when using it, but the other can be installed, but the driver is installed by the MODEM cannot be passed, the report I / O Repeat operation What is wrong with the MODEM driver?

Install's installation code is (DDK)

/ *

Copyright (c) 1999-2000 Microsoft Corporation

Module Name:

Install.c

Abstract:

Console App for the Installation of Device Drivers in Windows 2000.

ENVIRONMENT:

User Mode ONLY

NOTES:

This Code and Information Is Provided "As IS" without Warranty of Any

Kind, Either Expressed or Implied, Including But Not Limited to the THE

Implied Warranties of Merchantability and / or Fitness for a particular

Purpose.

Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.

Revision History:

9/22/99: Created Keith S. Garner, with input from eliyas and ta.

- * /

#include

#include // make all functions Unicode Safe.

#include

#include "newdev.h" // for the API UpdatedriverforPlugandPlayDevices ().

#include // for setupdixxx functions.

#define max_class_name_len 32 // stolen from

Int Displayerror (Tchar * ErrorName)

/ *

Routine Description:

THIS ROUTINE WILL DISPLAY THIS ROSTERROR in Human Readable

FORM WHEN POSSIBLE.

IF The Return Value IS A 32-bit Number, And Falls in The Range:

ERROR_NO_ASSOCIATED_CLASS 0XE0000200

TO

ERROR_CANT_REMOVE_DEVINST 0XE000000232

The value defined in setupapi.h can help to determine the error.

START by search for the text string error_no_associated_class.

Arguments:

ERRORNAME: Human Readable Description of the Last Function Called.

Return Value:

Allways returns false.

- * /

{

DWORD ERR = getLastError ();

LPVOID LPMESSAGEBUFFER = NULL;

IF (FormatMessage (Format_Message_Allocate_buffer | format_message_from_system,

NULL,

Err,

Makelangid (Lang_neutral, SUBLANG_DEFAULT),

(LPTSTR) & lpMessageBuffer,

0,

NULL))

_tprintf (Text ("% S Failure:% SN"), ErrorName, (Tchar *) lpMessageBuffer;

Else

_tprintf (Text ("% s failure: (0x% 08x) n"), errorname, err;

IF (lpMessageBuffer) localfree (lpMessageBuffer); // free system buffer

SetLastError (ERR);

Return False;

}

Bool FINDEXISTINGDEVICE (in LPTSTR HARDwareID)

/ *

Routine Description:

This Routine Finds An EXISTING DEVNODE IF PRESENT.

Arguments:

HardwareidList - Supplies A String Containing a Hardware ID To

Be associated with the device.

Return Value:

The Function Returns True if IT is successful.

OtherWise It Returns False and The Logged Error Can Be Retrieved

WITH a call to getLastError.

THE MOST Common Error Will Be Error_NO_MORE_ITEMS, WHICH Means The

Function Could Not Find A DevNode with the hardwareid.

- * /

{

HDEVINFO DeviceInfoset;

SP_DEVINFO_DATA DEVICEINFODATA; // The sp_devinfo_data structure defines a member of a device information set.

DWORD I, ERR;

Bool Found;

//

// CREATE A Device Information Set with all present devices.

//

DeviceInfoset = setupdigetClassdevs (null, // all classes

0,

0,

Digcf_allclasses | Digcf_Present); // All Devices Present On System

IF (DeviceInfoset == INVALID_HANDLE_VALUE)

{

Return DisplayError (Text ("" GetClassDevs (All Present Devices) ");

}

// _tprintf (Text ("Search for Device ID:"), HardwareID;

//

// Enumerate Through all devices.

//

Found = false;

DeviceInfodata.cbsize = sizeof (sp_devinfo_data);

For (i = 0; SetupdienumDeviceInfo (DeviceInfoseet, I, & DeviceInFodata); i ) {

DWORD DATAT;

LPTSTR P, BUFFER = NULL;

DWORD BUFFERSIZE = 0;

//

// We Won't know the size of the hardwareid buffer unsteil we call

// this function. so call it with a null to begin with, and the

// use the required buffer size to alloc the neticary space.

// Keep Calling We Have Success OR An Unknown Failure.

//

While (! setupdiGetDeviceRegistryProperty)

DeviceInfoseet,

& DeviceInFodata,

SPDRP_HARDWAREID,

& Datat,

(Pbyte) buffer,

Buffersize,

& buffersize))

{

IF (getLastError () == error_INVALID_DATA)

{

//

// May Be a legacy device with no hardwareid. Continue.

//

Break;

}

ELSE IF (getLastError () == error_insuffect_buffer

{

//

// we need to change the buffer size.

//

IF (buffer)

Localfree (buffer);

Buffer = localloc (lptr, buffersize);

}

Else

{

//

// unknown failure.

//

DisplayError (Text ("GetDeviceRegistryProperty));

Goto Cleanup_DeviceInfo;

}

}

IF (getLastError () == error_INVALID_DATA)

CONTINUE;

//

// Compare Each Entries In the buffer multi-sz list with our hardwareid.

//

For (P = Buffer; * P && (P <& Buffer [buffersize]); P = lstrlen (p) sizeof (tchar))

{

//_tprintf (Text ("Compare Device ID: [% S] N"), P);

IF (! _TCSCMP (HardwareID, P))

{

// _tprintf (text ("Found! [% s] n"), P);

Found = True;

Break;

}

}

IF (Buffer) Localfree (buffer);

IF (Found) Break;

}

IF (getLastError ()! = no_ERROR)

{

DisplayError (Text ("EnumDeviceInfo");

}

//

// cleanup.

//

Cleanup_DeviceInfo:

Err = getLastError ();

SetupdideStroyDeviceInfolist (DeviceInfoseet);

SetLastError (ERR);

Return Err == NO_ERROR; / /? ???}

Bool

InstallrootenumeratedDriver (in lPTSTR HardwareID,

In lPTSTR Infile,

Out PBOOL RebootRequired Optional

)

/ *

Routine Description:

This Routine Creates and Installs a new root-enumerated devnode.

Arguments:

HardwareidList - Supplies a Multi-Sz List Containing One or More Hardware

IDS to be associated with the device. These Are Necessary in ORDER

To match up with an inf Driver Node When We go to do the debrough

Installation.

Inffile - Supplies The Full Path to the inf file to be used

Installing this Device.

RebootRequired - Optionally, Supplies The Address of a Boolean That IS

Set, Upon Successful Return, To Indicate WHETHER or Not a Reboot IS

Required to bring the newly-installed device on-line.

Return Value:

The Function Returns True if IT is successful.

OtherWise It Returns False and The Logged Error Can Be Retrieved

WITH a call to getLastError.

- * /

{

HDEVINFO DeviceInfoset = 0;

Sp_devinfo_data deficeinfodata;

Guid ClassGUID;

Tchar classname [MAX_CLASS_NAME_LEN];

DWORD ERR;

//

// Use the inf file to extract the class guid.

//

IF (! SetupDiGetinfclass (Infile, & ClassGuid, ClassName, Sizeof (Classname), 0))

{

Return DisplayError (Text ("GetInfClass");

}

//

// Create the Container for the to-be-create DEvice Information ELEMENT.

//

DeviceInfoset = setupdicreateDeviceInfolist (& ClassGuid, 0);

IF (DeviceInfoset == INVALID_HANDLE_VALUE)

{

Return DisplayError (Text ("CreateDeviceInfolist");

}

//

// Now create the element.

// use the class guid and name from the inf file.

//

DeviceInfodata.cbsize = sizeof (sp_devinfo_data);

IF (! setupdicreateDeviceInfo (DeviceInfoseet,

Classname,

& Classguid, NULL,

0,

DICD_Generate_ID,

& DeviceInfodata)))

{

Displayerror (Text ("CreateDeviceInfo");

Goto Cleanup_DeviceInfo;

}

//

// add the hardwareid to the device's hardwareid property.

//

IF (! setupdiseEvicRegistryProperty (DeviceInfoseet,

& DeviceInFodata,

SPDRP_HARDWAREID,

(Lpbyte) HardwareID,

(LSTRLEN (HARDwareID) 1 1) * Sizeof (tchar)))))

{

DisplayError (Text ("SetDeviceRegistryProperty));

Goto Cleanup_DeviceInfo;

}

//

// Transform The Registry Element Into An Actual DevNode

// in The PNP HW Tree.

//

IF (! setupdicallclassinstaller (Dif_RegisterDevice,

DeviceInfoseet,

& DeviceInfodata)))

{

Displayerror (Text ("" CallClassInstaller (RegisterDevice) ")

Goto Cleanup_DeviceInfo;

}

//

// the element is now registered. We must explicitly remove the

// device using diff_remove, if we encounter Any Failure from now.

//

//

// install the driver.

//

if (! UpdatedriverforPlugandPlayDevices (0,

HardwareID,

Infile,

Installflag_force,

RebootRequired))

{

DWORD ERR = getLastError ();

DisplayError (Text ("UpdatedriverforPlugandPlayDevices))

IF (! setupdicallclassinstaller)

Dif_remove,

DeviceInfoseet,

& DeviceInfodata)))

{

DisplayError (Text ("CallClassInstaller (Remove)))

}

SetLastError (ERR);

}

//

// cleanup.

//

Cleanup_DeviceInfo:

Err = getLastError ();

SetupdideStroyDeviceInfolist (DeviceInfoseet);

SetLastError (ERR);

Return Err == NO_ERROR;

}

INT __CDECL _TMAIN (int Argc, _tchar ** argv, _tchar ** envp)

/ *

Routine Discription:

Entry point to install.exe.

Parse The Command Line, Call Subroutines.

Arguments:

Standard console 'c' Application Arguments.

Argv [1] - Full path of inf file.

Argv [2] - PNP Hardwareid of Device.Return Value:

Standard Console Errorlevel Values:

0 - INSTALL SUCCESSFULL, NO Reboot Required.

1 - Install SuccessFull, Reboot Required.

2 - install failure.

- * /

{

Win32_find_data findfiledata;

Bool rebootRequired = 0; // must be clear.

//

// verify the arguments.

//

IF (argc! = 3)

{

_tprintf (text ("Usage: install n"))))

Return 2; // Install Failure

}

IF (Findfirstfile (Argv [1], & FindFileData) == Invalid_Handle_Value)

{

_tprintf (Text ("File Not Found.n"));

_tprintf (text ("Usage: install n"))))

Return 2; // Install Failure

}

//

// Look to See IF this Device Allready Exists.

//

IF (FINDEXISTINGDEVICE (Argv [2])))

{

//

// no need to create a device node, Just Call Our API.

//

IF (! UpdatedriverforPlugandPlayDevices) (0, // No Window Handle

Argv [2], // Hardware ID

Argv [1], // filename

Installflag_force,

& RebootRequired))

{

DisplayError (Text ("UpdatedriverforPlugandPlayDevices))

Return 2; // Install Failure

}

}

Else

{

IF (getLastError ()! = error_no_more_items)

{

//

// An unknown failure from FindexistingDevice ()

//

Return 2; // Install Failure

}

//

// Driver Does Not Exist, Create and Call The API.

// Hardwareid Must Be a Multi-Sz String, Which Argv [2] IS.

//

IF (! installrootenumerateddriver) (argv [2], // hardwareid

Argv [1], // filename

& RebootRequired))

{

Return 2; // Install Failure

}

}

_tprintf (Text ("Driver Installed SuccessFully.N));

IF (RebootRequired)

{

_tprintf (text ("(" ("(Reboot Required)))));

Return 1; // install success, reboot required.

}

Return 0; // install success, no reboot required.

转载请注明原文地址:https://www.9cbs.com/read-15268.html

New Post(0)