none
Installing a class filter using SetUpApi's RRS feed

  • Question

  • Hi,
    I'm trying to install a KMDF based diskdrive upper filter using a device installation application as mentioned in the WDK online documentation

    As the link specifies the three SetUp  functions need to be called to process appropriate sections of the INF file.
    The inf file i've used is pretty much the same as the diskperf sample in WDK with changes made just to the names of the sys and inf files.

    Following is the app code i've written:

    hInf = SetupOpenInfFile(argv[1],NULL,INF_STYLE_WIN4,NULL);
    	if(hInf == INVALID_HANDLE_VALUE)
    	{
    		printf("SetupOpenInfFile failed\n argv[1] = %s\n error code %d\n",argv[1],GetLastError());
    		return FALSE;
    	}
    	fileQueue = SetupOpenFileQueue();
    	if((!fileQueue) || fileQueue == INVALID_HANDLE_VALUE)
    	{
    		printf("SetupOpenFileQueue failed with error %d\n",GetLastError());
    		SetupCloseInfFile(hInf);//close the handle to the inf file
    		return FALSE;
    	}
    	qContext = SetupInitDefaultQueueCallbackEx(NULL,NULL,0,0,NULL);
    	if(!qContext)
    	{
    		printf("SetupInitDefaultQueueCallbackEx failed \n");
    		SetupCloseFileQueue(fileQueue);
    		SetupCloseInfFile(hInf);
    		return FALSE;
    	}
    	bResult = SetupInstallFilesFromInfSection(hInf,NULL,fileQueue,"DefaultInstall",".",SP_COPY_NEWER_OR_SAME);
    	if(bResult)
    	{//Commit the queue to copy the files
    		bResult = SetupCommitFileQueue(NULL,fileQueue,(PSP_FILE_CALLBACK) SetupDefaultQueueCallback,qContext);
    		if(!bResult)
    		{
    			printf("SetupCommitFileQueue failed error %d\n",GetLastError());
    			SetupCloseFileQueue(fileQueue); 
    			SetupCloseInfFile(hInf);
    			return FALSE;
    		}
    	}
    	else
    	{
    		printf("SetupInstallFilesFromInfSection failed error %d\n",GetLastError());
    		SetupCloseFileQueue(fileQueue);
    		SetupCloseInfFile(hInf);
    		return FALSE;
    	}
    	bResult = SetupInstallServicesFromInfSection(hInf,"DefaultInstall",SPSVCINST_DELETEEVENTLOGENTRY);
    	if(!bResult)
    	{
    		printf("SetupInstallServicesFromInfSection failed error 0x%x\n",GetLastError());
    		DisplayError("SetupInstallServicesFromInfSection");
    		SetupCloseFileQueue(fileQueue);
    		SetupCloseInfFile(hInf);
    		return FALSE;
    	}
    	ZeroMemory(&diskDrive,sizeof(GUID));
    	ret = UuidFromString((RPC_CSTR)str1,&diskDrive);
    	if(ret == RPC_S_INVALID_STRING_UUID )
    	{
    		printf("UuidFromString() returns Invalid string GUID\n");
    		SetupCloseFileQueue(fileQueue);
    		SetupCloseInfFile(hInf);
    		return FALSE;
    	}
    	// Open handle to diskdrive class registry key
    	hClassKey = SetupDiOpenClassRegKey(&diskDrive,KEY_ALL_ACCESS);
    	if(hClassKey == INVALID_HANDLE_VALUE)
    	{
    		printf("SetupDiOpenClassRegKey() failed %d\n",GetLastError());
    		SetupCloseFileQueue(fileQueue);
    		SetupCloseInfFile(hInf);
    		return FALSE;
    	}
    	bResult = SetupInstallFromInfSection(NULL,hInf,"DefaultInstall",SPINST_REGISTRY,hClassKey,".",0,NULL,
    										NULL,NULL,NULL);
    	if(!bResult)
    	{
    		printf("SetupInstallFromInfSection failed with error code %d\n",GetLastError());
    	}
    	SetupCloseFileQueue(fileQueue);
    	SetupCloseInfFile(hInf);//close the handle to the inf file

    Couple of questions here:
    1. Is this correct??
    2. When i run the app i'm getting a error at SetupInstallServicesFromInfSection(). I'm not sure what flag parameter  to specify for this. If i give flags as SPSVCINST_STARTSERVICE/SPSVCINST_STARTSERVICE, i get a 0x1004(Invalid flag)  error code. For others GetLastError returns a huge negative number and the FormatMessage() gives a NULL.

    Any help on this would be appreciated.

    Monday, February 25, 2013 6:26 AM

Answers

  • this will not install KMDF, you will need to do that as well. the nonpnp sample, http://code.msdn.microsoft.com/windowshardware/NONPNP-5fb0fa62 , shows you how to call directly into the class installer to install KMDF. the docs clearly say that for SPSVCINST_STARTSERVICE

    AddService section: Start the service after the service is installed. This flag cannot be used to start a service that implements a Plug and Play (PnP) function driver or filter driver for a device. Otherwise, this flag can be used to start a user-mode or kernel-mode service that is managed by the Service Control Manager (SCM.)

    GetLastError() is only valid if the API returns an error and the APIs is documented to set GLE. Typically a huge negative number means it meant to be viewed as hex, not decimal, so post the hex value you are getting.


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, February 25, 2013 6:37 AM

All replies

  • this will not install KMDF, you will need to do that as well. the nonpnp sample, http://code.msdn.microsoft.com/windowshardware/NONPNP-5fb0fa62 , shows you how to call directly into the class installer to install KMDF. the docs clearly say that for SPSVCINST_STARTSERVICE

    AddService section: Start the service after the service is installed. This flag cannot be used to start a service that implements a Plug and Play (PnP) function driver or filter driver for a device. Otherwise, this flag can be used to start a user-mode or kernel-mode service that is managed by the Service Control Manager (SCM.)

    GetLastError() is only valid if the API returns an error and the APIs is documented to set GLE. Typically a huge negative number means it meant to be viewed as hex, not decimal, so post the hex value you are getting.


    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, February 25, 2013 6:37 AM
  • Thanks for the reply Doron. I'm looking at the NonPNP sample on how to install KMDF.

    The hex error value i'm getting for SetupInstallServicesFromInfSection() is 0xE0000101.

    Monday, February 25, 2013 6:56 AM
  • now look up the error values defined in setupapi.h to see what it means.  setupapi.h uses macros to define some error values, so a whole string search might not yield an answer, but a partial string search (such as "101") will probably get you there.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, February 25, 2013 6:58 AM
  • Hi ,
    As per Doron's suggestion i've included the non-pnp sample code in my device installation app.
    So i added the code to load the wdfcoinstaller in the app before calling the setup api's. The modification seems to be working fine as the coinstaller loading is succesfull.
    But i'm still unable to get rid of the error occuring due to SetupInstallServicesFromInfSection().
    I checked the error code 0x101 and the and it says ERROR_SECTION_NOT_FOUND.
    I had changed the function to specify the flag parameter as SPSVCINST_NOCLOBBER_DISPLAYNAME.
    so the fucntion call is

    bResult = SetupInstallServicesFromInfSection(hInf,"StorageFilter",SPSVCINST_NOCLOBBER_DISPLAYNAME);
    

    Rest of the setupapi code remains the same.

    Here is the inf file i'm using for the installation.

    [Version]
    signature = "$Windows NT$"
    Class=DiskDrive
    ClassGUID = {4d36e967-e325-11ce-bfc1-08002be10318}
    DriverPackageType=ClassFilter
    CatalogFile=StorageFilter.cat 
    
    [SourceDisksNames]
    1 = %ClasFilt.MediaDesc%
    
    [SourceDisksFiles]
    StorageFilter.sys = 1
    
    [DestinationDirs]
    DefaultDestDir = 12	; DIRID_DRIVERS
    
    [DefaultInstall.NT]
    CopyFiles = @StorageFilter.sys
    AddReg = ClassFilter_AddReg
     
    [ClassFilter_AddReg]
    HKLM, System\CurrentControlSet\Control\Class\{4d36e967-e325-11ce-bfc1-08002be10318}, UpperFilters, 0x00010008, StorageFilter
    
    [StorageFilter.NT.Services]
    AddService = StorageFilter, , StorageFilter_Service_Inst
    
    [StorageFilter_Service_Inst]
    DisplayName    = %ClasFilt.SvcDesc%
    ServiceType    = %SERVICE_KERNEL_DRIVER%
    StartType      = %SERVICE_BOOT_START%
    ErrorControl   = %SERVICE_ERROR_NORMAL%
    ServiceBinary  = %12%\StorageFilter.sys		;change clasfilt.sys to the name of your driver binary.
    LoadOrderGroup = "PnP Filter"
    
    ;
    ;--- ClassFilt Coinstaller installation ------
    ;
    
    [DestinationDirs]
    StorageFilter_CoInstaller_CopyFiles = 11
    
    [StorageFilter.NT.CoInstallers]
    AddReg=StorageFilter_CoInstaller_AddReg
    CopyFiles=StorageFilter_CoInstaller_CopyFiles
    
    [StorageFilter_CoInstaller_AddReg]
    HKR,,CoInstallers32,0x00010000, "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller"
    
    [StorageFilter_CoInstaller_CopyFiles]
    WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll
    
    [SourceDisksFiles]
    WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames
    
    [StorageFilter.NT.Wdf]
    KmdfService = StorageFilter, StorageFilter_wdfsect
    [StorageFilter_wdfsect]
    KmdfLibraryVersion = $KMDFVERSION$
    
    [Strings]
    ClasFilt.SvcDesc	= "Disk Upper Filter Driver"
    ClasFilt.MediaDesc 	= "Installation Disk #1 (StorageFilter)"
    SERVICE_KERNEL_DRIVER = 1
    SERVICE_BOOT_START    = 0
    SERVICE_ERROR_NORMAL  = 1
    The documentation says that the flag is related to addservice section which is present in my inf file...then why the error???
    Wednesday, February 27, 2013 7:13 AM
  • There is no section named "StorageFilter" in your inf.

    -- pa

    Wednesday, February 27, 2013 12:10 PM
  • But the Service installation section is named "[StorageFilter.NT.Services]" . I believe that's the section SetupInstallServicesFromInfSection is looking for...

    Wednesday, February 27, 2013 12:52 PM
  • you have to fully decorate the names IIRC, the auto detection/decoration of section names only occurs when pnp is processing the inf

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, February 27, 2013 5:27 PM