I am new in device driver programming. I have written a co-installer to when USB device plugged in machine, the co-installer DLL should be called but it is not called. Below is the co-installer DLL code, which I have written:
#include <windows.h>
#include <setupapi.h>
#include <stdio.h>
//#include “resource.h”
//#include <dontuse.h>
//±--------------------------------------------------------------------------
//
// WARNING!
//
// Installer must not generate any popup to the user.
// It should provide appropriate defaults.
//
// OutputDebugString should be fine…
//
#if DBG
#define DbgOut(Text) OutputDebugString(TEXT(“ClassInstaller: " Text “\n”))
#else
#define DbgOut(Text)
#endif
DWORD CALLBACK
ClassInstaller(
in DI_FUNCTION InstallFunction,
in HDEVINFO DeviceInfoSet,
_in PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
)
/++
Routine Description:
Responds to Class-installer messages
.
Arguments:
InstallFunction [in]
DeviceInfoSet [in]
DeviceInfoData [in]
Return Value:
Returns: NO_ERROR, ERROR_DI_POSTPROCESSING_REQUIRED, or an error code.
–/
{
DWORD dwRegType, UINumber;
TCHAR szTest[80];
switch (InstallFunction)
{
case DIF_INSTALLDEVICE:
//
// Sent twice: once before installing the device and once
// after installing device, if you have returned
// ERROR_DI_POSTPROCESSING_REQUIRED during the first pass.
//
MessageBox(NULL,L"DIF_INSTALLDEVICE",Title,MB_OK);
DbgOut(“DIF_INSTALLDEVICE”);
break;
case DIF_ADDPROPERTYPAGE_ADVANCED:
//
// Sent when you check the properties of the device in the
// device manager.
//
MessageBox(NULL,L"DIF_ADDPROPERTYPAGE_ADVANCED",Title,MB_OK);
DbgOut(“DIF_ADDPROPERTYPAGE_ADVANCED”);
break;
//return PropPageProvider(DeviceInfoSet, DeviceInfoData);
case DIF_POWERMESSAGEWAKE:
//
// Sent when you check the power management tab
//
MessageBox(NULL,L"DIF_POWERMESSAGEWAKE",Title,MB_OK);
DbgOut(“DIF_POWERMESSAGEWAKE”);
break;
case DIF_PROPERTYCHANGE:
//
// Sent when you change the property of the device using
// SetupDiSetDeviceInstallParams. (Enable/Disable/Restart)
//
MessageBox(NULL,L"DIF_PROPERTYCHANGE",Title,MB_OK);
DbgOut(“DIF_PROPERTYCHANGE”);
break;
case DIF_REMOVE:
//
// Sent when you uninstall the device.
//
MessageBox(NULL,L"DIF_REMOVE",Title,MB_OK);
DbgOut(“DIF_REMOVE”);
break;
case DIF_NEWDEVICEWIZARD_FINISHINSTALL:
//
// Sent near the end of installation to allow
// an installer to supply wizard page(s) to the user.
// These wizard pages are different from the device manager
// property sheet.There are popped only once during install.
//
MessageBox(NULL,L"DIF_NEWDEVICEWIZARD_FINISHINSTALL",Title,MB_OK);
DbgOut(“DIF_NEWDEVICEWIZARD_FINISHINSTALL”);
break;
case DIF_SELECTDEVICE:
MessageBox(NULL,L"DIF_SELECTDEVICE",Title,MB_OK);
DbgOut(“DIF_SELECTDEVICE”);
break;
case DIF_DESTROYPRIVATEDATA:
//
// Sent when Setup destroys a device information set
// or an SP_DEVINFO_DATA element, or when Setup discards
// its list of co-installers and class installer for a device
//
MessageBox(NULL,L"DIF_DESTROYPRIVATEDATA",Title,MB_OK);
DbgOut(“DIF_DESTROYPRIVATEDATA”);
break;
case DIF_INSTALLDEVICEFILES:
MessageBox(NULL,L"DIF_INSTALLDEVICEFILES",Title,MB_OK);
DbgOut(“DIF_INSTALLDEVICEFILES”);
break;
case DIF_ALLOW_INSTALL:
//
// Sent to confirm whether the installer wants to allow
// the installation of device.
//
MessageBox(NULL,L"DIF_ALLOW_INSTALL",Title,MB_OK);
DbgOut(“DIF_ALLOW_INSTALL”);
break;
case DIF_SELECTBESTCOMPATDRV:
MessageBox(NULL,L"DIF_SELECTBESTCOMPATDRV",Title,MB_OK);
DbgOut(“DIF_SELECTBESTCOMPATDRV”);
break;
case DIF_INSTALLINTERFACES:
MessageBox(NULL,L"DIF_INSTALLINTERFACES",Title,MB_OK);
DbgOut(“DIF_INSTALLINTERFACES”);
break;
case DIF_REGISTER_COINSTALLERS:
MessageBox(NULL,L"DIF_REGISTER_COINSTALLERS",Title,MB_OK);
DbgOut(“DIF_REGISTER_COINSTALLERS”);
break;
default:
MessageBox(NULL,L"default",Title,MB_OK);
DbgOut("DIF???”);
break;
}
return NO_ERROR;;
}
Note:
1. This dll I have copied in system32 folder and Installed the driver.
Case1: When I plugged the USB device the co-installer DLL is not called after install the our device driver.
Case2: When Uninstalled the driver, then Inserting the USB device, the co-installer DLL is called.
Case3: when updating the driver from the device manager that time also called the co-installer DLL.
Only failure occur in case 1.
Thanks in advance.</dontuse.h></stdio.h></setupapi.h></windows.h>