예제 #1
0
파일: coinst.c 프로젝트: OwenSmith/xenhid
DWORD CALLBACK
Entry(
    IN  DI_FUNCTION                 Function,
    IN  HDEVINFO                    DeviceInfoSet,
    IN  PSP_DEVINFO_DATA            DeviceInfoData,
    IN  PCOINSTALLER_CONTEXT_DATA   Context
    )
{
    HRESULT                         Error;

    Log("%s (%s) ===>",
        MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
        DAY_STR "/" MONTH_STR "/" YEAR_STR);

    if (!Context->PostProcessing) {
        Log("%s PreProcessing",
            __FunctionName(Function));
    } else {
        Log("%s PostProcessing (%08x)",
            __FunctionName(Function),
            Context->InstallResult);
    }

    switch (Function) {
    case DIF_INSTALLDEVICE: {
        SP_DRVINFO_DATA         DriverInfoData;
        BOOLEAN                 DriverInfoAvailable;

        DriverInfoData.cbSize = sizeof (DriverInfoData);
        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
                                                       DeviceInfoData,
                                                       &DriverInfoData) ?
                              TRUE :
                              FALSE;

        // If there is no driver information then the NULL driver is being
        // installed. Treat this as we would a DIF_REMOVE.
        Error = (DriverInfoAvailable) ?
                DifInstall(DeviceInfoSet, DeviceInfoData, Context) :
                DifRemove(DeviceInfoSet, DeviceInfoData, Context);
        break;
    }
    case DIF_REMOVE:
        Error = DifRemove(DeviceInfoSet, DeviceInfoData, Context);
        break;
    default:
        if (!Context->PostProcessing) {
            Error = NO_ERROR;
        } else {
            Error = Context->InstallResult;
        }

        break;
    }

    Log("%s (%s) <===",
        MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
        DAY_STR "/" MONTH_STR "/" YEAR_STR);

    return (DWORD)Error;
}
예제 #2
0
__user_code  

#include <windows.h>
#include <setupapi.h>
#include <stdio.h>
#include <strsafe.h>

//+---------------------------------------------------------------------------
//
// WARNING!
//
// A Coinstaller must not generate any popup to the user.
//     it should provide appropriate defaults.
//
//  OutputDebugString should be fine...
//
#if DBG
#define DbgOut(Text) OutputDebugString(TEXT("CoInstaller: " Text "\n"))
#else
#define DbgOut(Text)
#endif

//+---------------------------------------------------------------------------
//
//  Function:   MyOpenInfFile
//
//  Purpose:    Will open the handle to the INF file being installed
//
//  Arguments:
//      DeviceInfoSet     [in]
//      DeviceInfoData    [in]
//      ErrorLine         [out] // Optional, See SetupOpenInfFile
//
//  Returns:    HINF Handle of INF file
//
HINF MyOpenInfFile (
                    _In_      HDEVINFO          DeviceInfoSet,
                    _In_      PSP_DEVINFO_DATA  DeviceInfoData,
                    _Out_opt_ PUINT             ErrorLine
                    )
{
    SP_DRVINFO_DATA DriverInfoData;
    SP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
    DWORD Status;
    HINF FileHandle;

    if (NULL != ErrorLine)
    {
        *ErrorLine = 0;
    }

    DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
    if (!SetupDiGetSelectedDriver( DeviceInfoSet,
        DeviceInfoData,
        &DriverInfoData))
    {
        DbgOut("Fail: SetupDiGetSelectedDriver");
        return INVALID_HANDLE_VALUE;
    }

    DriverInfoDetailData.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
    if (!SetupDiGetDriverInfoDetail(DeviceInfoSet,
        DeviceInfoData,
        &DriverInfoData,
        &DriverInfoDetailData,
        sizeof(SP_DRVINFO_DETAIL_DATA),
        NULL))
    {
        if ((Status = GetLastError()) == ERROR_INSUFFICIENT_BUFFER)
        {
            // We don't need the extended information.  Ignore.
        }
        else
        {
            DbgOut("Fail: SetupDiGetDriverInfoDetail");
            return INVALID_HANDLE_VALUE;
        }
    }

    if (INVALID_HANDLE_VALUE == (FileHandle = SetupOpenInfFile(
        DriverInfoDetailData.InfFileName,
        NULL,
        INF_STYLE_WIN4,
        ErrorLine)))
    {
        DbgOut("Fail: SetupOpenInfFile");
    }
    return FileHandle;
}