65.9K
CodeProject is changing. Read more.
Home

Iterate and Extract Cabinet File

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.95/5 (14 votes)

May 25, 2004

CPOL
viewsIcon

79543

downloadIcon

2154

Iterate and extract Cabinet File

Introduction

The .NET Framework doesn't provide us with Cabinet File functionality through the programming interface. However, the Setupapi.dll enables us to handle cabinet files except for compressing. This TCabinet class encapsulates some functions of the Setupapi.dll in order to iterate and extract a cabinet file.

Background

TCabinet class encapsulates the following functions in setupapi.dll:

[DllImport("SetupApi.dll", CharSet=CharSet.Auto)]
public static extern bool SetupIterateCabinet(string cabinetFile, 
                    uint reserved, PSP_FILE_CALLBACK callBack, uint context); 

public delegate uint PSP_FILE_CALLBACK(uint context, uint notification, 
                                       IntPtr param1, IntPtr param2);


private uint CallBack(uint context, uint notification, IntPtr param1, 
                     IntPtr param2)
{
    uint rtnValue = SetupApiWrapper.NO_ERROR;
    switch (notification)
    { 
        case SetupApiWrapper.SPFILENOTIFY_FILEINCABINET:
            rtnValue = OnFileFound(context, notification, param1, param2);
            break;
        case SetupApiWrapper.SPFILENOTIFY_FILEEXTRACTED:
            rtnValue = OnFileExtractComplete(param1);
            break;
        case SetupApiWrapper.SPFILENOTIFY_NEEDNEWCABINET:
            rtnValue = SetupApiWrapper.NO_ERROR;
        break;
    }
    return rtnValue;
}

History

  • 25th May, 2004: Initial post