How to use SetupIterateCabinet with C#
<p>I am attempting to write code to extract the contents of a CAB file, however I am having trouble using the SetupIterateCabinet routine.</p>

<p>Please see doc here <a href="http://msdn.microsoft.com/en-us/library/aa377404(v=vs.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa377404(v=vs.85).aspx</a></p>

<p>I can import it properly like this</p>

<pre><code>    private const uint SPFILENOTIFY_CABINETINFO = 0x00000010;
    private const uint SPFILENOTIFY_FILEINCABINET = 0x00000011;
    private const uint SPFILENOTIFY_NEEDNEWCABINET = 0x00000012;
    private const uint SPFILENOTIFY_FILEEXTRACTED = 0x00000013;
    private const uint SPFILENOTIFY_FILEOPDELAYED = 0x00000014;
    private const uint NO_ERROR = 0;

    private const uint FILEOP_ABORT = 0;
    private const uint FILEOP_DOIT=                     1;
    private const uint FILEOP_SKIP=                     2;
    private const uint FILEOP_NEWPATH=                  4;

    static void Main(string[] args)
    {
        SetupIterateCabinet("c:\\SomeCab.cab", 0, new PSP_FILE_CALLBACK(CallBack), 0);


        Console.ReadKey();
    }

    [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 static uint CallBack(uint context, uint notification, IntPtr param1,
                         IntPtr param2)
    {
        uint rtnValue = NO_ERROR;
        switch (notification)
        {
            case SPFILENOTIFY_FILEINCABINET:
                rtnValue = OnFileFound(context, notification, param1, param2);
                break;
            case SPFILENOTIFY_FILEEXTRACTED:
                rtnValue = OnFileExtractComplete(param1);
                break;
            case SPFILENOTIFY_NEEDNEWCABINET:
                rtnValue = NO_ERROR;
                break;
        }
        return rtnValue;
    }

    private static uint OnFileExtractComplete(IntPtr param1)
    {
        Console.WriteLine("Complete");
        return FILEOP_DOIT;
    }


    [StructLayout(LayoutKind.Sequential)]
    struct _FILE_IN_CABINET_INFO {
        IntPtr NameInCabinet;
        int FileSize;
        int Win32Error;
        int  DosDate;
        int  DosTime;
        int  DosAttribs;
        StringBuilder FullTargetName;
    };

    static private uint OnFileFound(uint context, uint notification, IntPtr param1, IntPtr param2)
    {
        _FILE_IN_CABINET_INFO fc = new _FILE_IN_CABINET_INFO() ;
        Marshal.PtrToStructure(param1, fc);

        return 1;
    }
</code></pre>

<p>However the problem comes when attempting to process the SPFILENOTIFY_FILEINCABINET event in the callback.  According to the documentation this is a struct, that I need to put the name of where I want to have the file extracted to in.  I am having trouble figuring out what the struct should look like and maybe how to convert the param to a struct.</p>
