none
Custom icon fails to get picked up in the device manager tree in Windows 7 RRS feed

  • Question

  • Hello,

    I have a resource DLL that has a custom icon compiled with it that I want to use for my Windows 7 driver. The problem is, the device manager doesn't seem to be picking up the icon for display in the device tree. This same DLL when compiled for Windows XP is picked up fine in the XP device manager tree.

    The DLL is picked up and signed as part of my driver package, and I can see it in the C:\Windows\System32 folder where I think it belongs after the driver package is installed.

    My INF file settings to get the resource DLL picked up are as follows:

    [ClassInstall32.NTamd64]
    Addreg = MyIconClass

    [MyIconClass]
    HKR,,,,%ClassName%                                           ; Filled in by my [strings] section
    HKR,,EnumPropPages32,,"MyResource.dll,MyResourceEntryPoint"  ; Per MSDN
    HKR,,Icon,,"0"  ; 0 comes from the first icon in the DLL build, quotes on 0 have no effect

    I am fairly certain I've verified the export of the entry point and the DLL are implemented according to MSFT rules.

    What is puzzling me is the error I see in the SetupApi.log file when I open the device manager and select my device driver.

    The log entries are:

    !!! dvi: Loading module C:\WIndows\System32\MyResource.dll failed.
    !!! dvi: Error 126: The specified module could not be found.

    I'm confused... because I can clearly the MyResource.dll file in my C:\Windows\System32 folder.

    When I remove MyResource.dll from my driver package and open the device manager to view the (default) property sheet, which looks the same as when my DLL was part of the package, I don't see any errors in the SetupApi.log file.

    I'm using VS2012 and the Windows 8 WDK to build and sign my driver.

    I could probably try a different approach to loading the icon inside my INF, but so far as I can tell, the "EnumPropPages32" is the preferred method.

    If anyone has an idea why my icon might not be loading, I would sure appreciate a pointer or two...

    Thanks in advance for taking the time to read this.

    Geoff

    Friday, December 21, 2012 3:43 PM

Answers

  • 1) What kind of device is this a driver for?  Why does it need to define a new class?

    2) I don't believe that an index of 0 is allowed per the documentation of the device class property at http://msdn.microsoft.com/en-us/library/windows/hardware/ff542299(v=vs.85).aspx .

    If using an index other than 0 does not fix your problem, are you able to share the INF with us?

    Friday, December 21, 2012 4:53 PM
  • As for adding the icon, you added the AddProperty to your class install section.  You should be adding it to your DDInstall section.  i.e. in the full INF you copied earlier, it would go under the section [MY_DEVICE.NTamd64].  If you do this, you could use a system defined class if one is appropriate (e.g. System) and not define your own class.

    • Marked as answer by Geoff Cottrell Thursday, January 3, 2013 3:34 PM
    Wednesday, January 2, 2013 10:24 PM

All replies

  • 1) What kind of device is this a driver for?  Why does it need to define a new class?

    2) I don't believe that an index of 0 is allowed per the documentation of the device class property at http://msdn.microsoft.com/en-us/library/windows/hardware/ff542299(v=vs.85).aspx .

    If using an index other than 0 does not fix your problem, are you able to share the INF with us?

    Friday, December 21, 2012 4:53 PM
  • Thank you very much Jason for your reply, and Happy New Year!

    Thanks for the pointer on the index of zero for the icon. I will have to go back to see where I read that zero was the right thing to use... based on your link, 0 is not correct for my application.

    At any rate, changing the index to a positive number did not address my issue.

    The device is a commercially available high speed data comm card. I think the only reason there is a new class here is so we can use a custom icon that was compiled into a resource DLL, so we can identify the card running our custom driver for it in the device tree.

    Below is a copy of the INF file I am using. Thank you very much for taking the time to have a look at this.

    ;
    [Version]
    Signature   = "$WINDOWS NT$"
    Class       = My_Hardware
    ClassGuid   = {2C6AC053-4EC5-48FA-B626-A34230B94D09}
    Provider    = %Mfg%
    CatalogFile = MyDriver.cat
    DriverVer   = 1/2/2013, 1.0.0.0

    [SourceDisksNames]
    1 = %DiskId%

    [SourceDisksFiles.amd64]
    MyDriver.sys   = 1
    MyResource.dll = 1
    fileA.bin      = 1
    fileB.bin      = 1

    [DestinationDirs]
    DLL_Files_NTamd64 = 10,system32
    DefaultDestDir    = 12

    [ClassInstall32.NTamd64]
    Addreg = MyIconClass

    [MyIconClass]
    HKR,,,,%ClassName%
    HKR,,EnumPropPages32,,"MyResource.dll,MyResourceEntryPoint"
    HKR,,Icon,,"101"                                            ; was formerly "0", arbitrary non neg #'s have no effect

    [ControlFlags]
    ExcludeFromSelect = *

    [Manufacturer]
    %Mfg% = MyCompany, NTamd64

    [MyCompany.NTamd64]
    %DeviceDesc% = MY_DEVICE, PCI\VEN_xxxx&DEV_yyyy&SUBSYS_mmmmnnnn&REV_zz

    [MY_DEVICE.NTamd64]
    DriverVer = 1/2/2013, 1.0.0.0
    CopyFiles = Common_Files,Common_Files_NTamd64,DLL_Files_NTamd64

    [Common_Files]
    fileA.bin
    fileB.bin

    [Common_Files_NTamd64]
    MyDriver.sys

    [DLL_Files_NTamd64]
    MyResource.dll

    [MY_DEVICE.NTamd64.Services]
    AddService = MyDriver, %SPSVCINST_ASSOCSERVICE%, My_Service_Inst_NTamd64, My_EventLog_Inst_NTamd64

    [My_Service_Inst_NTamd64]
    DisplayName    = %ServiceDisp%
    Description    = %ServiceDesc%
    ServiceType    = %SERVICE_KERNEL_DRIVER%
    StartType      = %SERVICE_DEMAND_START%
    ErrorControl   = %SERVICE_ERROR_NORMAL%
    ServiceBinary  = %12%\MyDriver.sys
    DelReg         = Clear_My_Parms
    AddReg         = My_Parms

    [Clear_My_Parms]
    HKR, Parameters

    [My_Parms]
    HKR, Parameters, fileAParm, %ADDREG_TYPE_SZ%, "\SystemRoot\System32\Drivers\fileA.bin"
    HKR, Parameters, fileBParm, %ADDREG_TYPE_SZ%, "\SystemRoot\System32\Drivers\fileB.bin"

    [My_EventLog_Inst_NTamd64]
    AddReg = My_EventLog_AddReg_NTamd64

    [My_EventLog_AddReg_NTamd64]
    HKR, , TypesSupported,   %ADDREG_TYPE_DWORD%, 7
    HKR, , EventMessageFile, %ADDREG_TYPE_EXPSZ%, "%%SystemRoot%%\System32\Drivers\MyDriver.sys"

    [Strings]
    ClassName              = "My Driver Class Name"
    DeviceDesc             = "My Device Description"
    ServiceDisp            = "My Device Driver"
    ServiceDesc            = "My service description."
    DiskId                 = "My Driver Install Disk"
    Mfg                    = "My Company, Inc."
    SPSVCINST_ASSOCSERVICE = 0x00000002
    SERVICE_KERNEL_DRIVER  = 1
    SERVICE_DEMAND_START   = 3
    SERVICE_DISABLED       = 4
    SERVICE_ERROR_NORMAL   = 1
    ADDREG_TYPE_DWORD      = 0x00010001
    ADDREG_TYPE_SZ         = 0x00000000
    ADDREG_TYPE_EXPSZ      = 0x00020000

    Wednesday, January 2, 2013 6:22 PM
  • You do not need to define a new class to change the icon of a device.  You can specify an icon for a device from an INF by doing an AddProperty to add the DeviceIcon property (http://msdn.microsoft.com/en-us/library/windows/hardware/ff546318(v=vs.85).aspx ).

    I am not sure of the cause of not being able to find your DLL.  Is MyResourceEntryPoint correctly exported from the DLL?  Does the DLL have a DllMain?  Has your system modified the DLL search order at all?

    Wednesday, January 2, 2013 8:06 PM
  • Thank you again Jason for looking at this...

    I have a DLLMain() function, setup according to http://msdn.microsoft.com/en-us/library/windows/desktop/ms682596(v=vs.85).aspx

    And... I think I've exported MyResourceEntryPoint() correctly, using this method:

    BOOL __declspec(dllexport) MyResourceEntryPoint(
      PSP_PROPSHEETPAGE_REQUEST pPropPageRequest,
      LPFNADDPROPSHEETPAGE fAddFunc,
      LPARAM lParam)

    { return TRUE; }

    I am not sure if the system DLL search order has been modified, but I would guess 'no' unless I've defiled it accidentally whilst trying to get the icon to show up...

    I tweaked my INF file so that I had the following lines included to see if the AddProperty suggestion would work. I used the guidelines from the whitepaper "Creating Custom Device Icons", found at link: http://msdn.microsoft.com/en-us/library/windows/hardware/gg463057.aspx

    [ClassInstall32.NTamd64]
    ;Addreg = MyIconClass

    AddProperty = MyIconClass

    [MyIconClass]
    ;HKR,,,,%ClassName%
    ;HKR,,EnumPropPages32,,"MyResource.dll,MyResourceEntryPoint"
    ;HKR,,Icon,,"101"                                            ; was formerly "0", arbitrary non neg #'s have no effect

    DeviceIcon,,,,"%windir%\system32\MyResource.dll,-101"  ; must be < 0, no value makes a difference here....

    Changing these lines in my INF didn't help, so I am going to guess I've screwed up the code/compile of the DLL for Windows 7 somehow, and did not create/compile/export the DLLMain and call back (entry point) functions properly. It makes no sense to me why windows can't find the DLL, even though it's clearly installed in the path where it's supposed be.

    If anything here looks out of place, please let me know if you get a chance. I'm going to go back to the DLL to see if there's something else I missed/screwed up.

    Thanks!

    Geoff

    Wednesday, January 2, 2013 10:06 PM
  • __declspec(dllexport) exports a somewhat mangled name.  run link /dump /exports <yourdll> to see the true name being exported. I am guessing it has a _ in the name, perhaps an @.  You want to use a .def file where you can control the exported name. Also, you should explicitly put the calling convention in the function declaration, otherwise stack corruption may ensue if you ever change the default calling convention on the cl command line.

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

    Wednesday, January 2, 2013 10:11 PM
  • Thanks for the tip Doron, I will try this out shortly. For what it's worth, I do have a .def file, formatted as follows:

    LIBRARY  MyResource.dll
    HEAPSIZE 8192

    EXPORTS
     DllMain
     MyResourceEntryPoint

    I will get back to you on the output of the link command as soon as I can locate its path on my test platform.

    Thanks!

    Geoff

    Wednesday, January 2, 2013 10:17 PM
  • As for adding the icon, you added the AddProperty to your class install section.  You should be adding it to your DDInstall section.  i.e. in the full INF you copied earlier, it would go under the section [MY_DEVICE.NTamd64].  If you do this, you could use a system defined class if one is appropriate (e.g. System) and not define your own class.

    • Marked as answer by Geoff Cottrell Thursday, January 3, 2013 3:34 PM
    Wednesday, January 2, 2013 10:24 PM
  • Interesting... I ran the "link" command, and it did not output anything...

    When I examine the DLL with a binary editor, I can see the icon file embedded in there, so I will have to keep digging.

    It cannot be good that "link" did not output any symbols.

    Thanks for the tip Doron, I will continue looking here for my issue.

    Geoff

    Wednesday, January 2, 2013 10:48 PM
  • just to make sure you did the right thing, can you post the command you ran and the output? also make sure that your .def file is being used during the link phase, look at the build logs to make sure it is being passed to link under the /DEF command line option.

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

    Wednesday, January 2, 2013 10:56 PM
  • I was a little suspicious too... I'll double check the logs to make sure it's being picked up and let you know

    I ran dumpbin instead, and actually got some output, link doesn't seem to be working properly on my Windows 7 machines... Anyway, here's the output from dumpbin:

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64>dumpbin.exe /exports C:\MyResource.DLL
    Microsoft (R) COFF/PE Dumper Version 11.00.50727.1
    Copyright (C) Microsoft Corporation.  All rights reserved.


    Dump of file C:\MyResource.DLL

    File Type: DLL

      Section contains the following exports for MyResource.dll

        00000000 characteristics
        50E4BBF3 time date stamp Wed Jan 02 17:00:03 2013
            0.00 version
               1 ordinal base
               2 number of functions
               2 number of names

        ordinal hint RVA      name

              1    0 00001020 DllMain = DllMain
              2    1 00001000 MyResourceEntryPoint = MyResourceEntryPoint

      Summary

            1000 .data
            1000 .pdata
            2000 .rdata
            1000 .reloc
            1000 .rsrc
            1000 .rtc
            2000 .text

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64>

    Wednesday, January 2, 2013 11:08 PM
  • The def file is being picked up.
    Wednesday, January 2, 2013 11:10 PM
  • one way to verify that the export is truly working is to write a little test application that calls LoadLibrary("MyResource.dll") and then GetProcAddress("MyResourceEntryPoint") and see if both are successful.  the other thing that could be stopping you is an unresolved import.  if you are linking against the VS CRT, you will need to run the VS provided CRT installer that installs the CRT to satisfy your imports.

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

    Wednesday, January 2, 2013 11:56 PM
  • Jason and Doran, you guys are awesome. Thanks for the tips. I'm going to try them out this morning and I'll let you know what happens. I really, really appreciate your time and the pointers you've given me.
    Thursday, January 3, 2013 2:40 PM
  • Moving the AddProperty to the appropriate section in my INF solved my problem. My custom icon shows up now. I'm still seeing the error about loading the DLL from the SetupApi.log, so I'm going to continue with checking on the symbols using Doron's suggested experiment.

    Thanks again guys. If you're ever in Chicago, shoot me an email and I'll buy dinner! I really appreciate all your help. You guys are great.

    Thanks again!

    Geoff

    Thursday, January 3, 2013 3:38 PM
  • Sorry I spelled your name wrong there, Doron...

    Thursday, January 3, 2013 3:39 PM
  • A final update on the errors reported in the SetupApi.app log file:

    I performed a clean install of Windows 7 x64 Pro on the PC where I was doing most of my debug/development, and reinstalled the driver. There are no errors being reported when trying to load the DLL now, so I think I must have messed up something during the course of many downloads and installs of the driver code to my target PC.

    Thanks again for all your help!

    Geoff

    Friday, January 4, 2013 6:22 PM