Okay... Here's more detailed code showing what I'm doing:
public class PkCdl {
public const int FORMAT_MESSAGE_ FROM_SYSTEM = 0x00001000;
[ DllImport( "Kernel32.d ll" )]
public static extern int FormatMessage(i nt flags, IntPtr source, int
messageId, int languageId, StringBuilder buffer, int size, IntPtr
arguments);
[DllImport("PKCD L.DLL", EntryPoint="pkc rc32",
CallingConventi on=CallingConve ntion.Cdecl)]
public static extern int Crc32(IntPtr buffer, UInt32 size, int oldCrc);
[DllImport("PKCD L.DLL", EntryPoint="pke xplode", CharSet=CharSet .Auto,
CallingConventi on=CallingConve ntion.Cdecl, SetLastError=tr ue)]
public static extern UInt32 Explode(ReadHan dler reader, WriteHandler
writer, IntPtr buffer, ref object param);
[DllImport("PKCD L.DLL", EntryPoint="pki mplode", CharSet=CharSet .Auto,
CallingConventi on=CallingConve ntion.Cdecl, SetLastError=tr ue)]
public static extern UInt32 Implode(ReadHan dler reader, WriteHandler
writer, IntPtr buffer, ref object param, DCLDataType cmdType,
DCLDictionarySi ze dsize);
[DllImport("PKCD L.DLL", EntryPoint="pkG etBufferSize",
CallingConventi on=CallingConve ntion.Cdecl)]
public static extern int GetBufferSize(i nt type);
public static string LastWin32Messag e() {
int errCode = Marshal.GetLast Win32Error();
StringBuilder buffer = new StringBuilder(2 56);
FormatMessage(F ORMAT_MESSAGE_F ROM_SYSTEM, IntPtr.Zero, errCode, 0,
buffer, buffer.Capacity , IntPtr.Zero);
return buffer.ToString ();
}
}
public delegate int ReadHandler(Int Ptr buffer, UInt32 size, ref object
param);
public delegate void WriteHandler(In tPtr buffer, UInt32 size, ref object
param);
public UInt32 ReadData(IntPtr buffer, UInt32 size, ref object param) {
try {
byte[] values = archiveReader.R eadBytes(Conver t.ToInt32(size) );
Marshal.Copy(va lues, 0, buffer, values.Length);
return Convert.ToUInt3 2(values.Length );
} catch (Exception ex) {
string msg = ex.Message;
return 0;
}
}
public void WriteData(IntPt r buffer, UInt32 size, ref object param) {
try {
byte[] values = new byte[size];
Marshal.Copy(bu ffer, values, 0, Convert.ToInt32 (size));
outWriter.Write (values); // Write output to where ever
} catch (Exception ex) {
string msg = ex.Message;
}
}
// Actual code invocation
int bufferSize = GetBufferSize(D CLBufferType.PK EXT,
DCLAlgorithmTyp e.DCLIMPLODE);
IntPtr buffer = Marshal.AllocHG lobal(bufferSiz e); // 12596
try {
object data = this;
ReadHandler rh = new ReadHandler(Rea dData);
WriteHandler wh = new WriteHandler(Wr iteData);
UInt32 status = PkCdl.Explode(r h, wh, buffer, ref data);
} finally {
Marshal.FreeHGl obal(buffer);
}
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!