Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Iterate and Extract Cabinet File

0.00/5 (No votes)
24 May 2004 1  
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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here