Copy Code code as follows:
public class Lhautity
{
Get version of DLL
[DllImport ("Unlha32")]
private static extern UInt16 unlhagetversion ();
<summary>
' Get the implementation of the DLL
</summary>
<returns> Success </returns>
[DllImport ("Unlha32")]
private static extern Boolean unlhagetrunning ();
///<summary>
/ ' File check
///</summary>
///<param name= "szFileName" ></PARAM>
/// <param name= "Imode" ></PARAM>
///<returns></ Returns>
[DllImport ("Unlha32")]
private static extern Boolean unlhacheckarchive (String szfilename, Int32 imode);
///<summary>
/ File decompression
///</summary>
///<param name= "hwnd" ></PARAM>
///< param name= "szCmdLine" ></PARAM>
///<param name= " Szoutput "></param>
///<param name=" dwsize "></ Param>
///<returns></returns>
[DllImport ("Unlha32")]
Private static extern int Unlha (int hwnd, string szcmdline, string szoutput, int dwsize);
///<summary>
/ Files that need to be unzipped
///</summary>
///<param name= "Archivefile" > Extract file path </param>
///<param name= "Extractdir" > Extract to Path </param>
/// <param name= "Isdeletefile" > Delete </param>
public static BOOL Uncompress (String archivefile, String extractdir,bool isdeletefile)
{
string extractfullpath = String. Empty;
String Startpath = AppDomain.CurrentDomain.BaseDirectory;
if (! System.IO.File.Exists (archivefile))
{
//Judge the files that need to be extracted cannot be saved
throw New Exception ( String. Format ("{0} that needs to be decompressed does not exist", archivefile));
}
Try
{
UInt16 ver = lhautity.unlhagetversion ();
}
catch (Exception ex)
{
throw new Exception ("Unlha32.dll File not Found");
}
if (unlhagetrunning ())
{
throw new Exception ("DLL executing");
}
if (! Unlhacheckarchive (archivefile, 0))
{
throw new Exception ("File cannot be decompressed");
}
//unzipped path
if (string. IsNullOrEmpty (Extractdir))
{
Extractfullpath =string. Format (@ "{0}{1}\", startpath,archivefile.substring (Archivefile.lastindexof ("\") +1,archivefile.indexof (". Lha")- 1-archivefile.lastindexof ("\)"));
}
Else
{
Extractfullpath = Extractdir;
}
if (! System.IO.Directory.Exists (Extractfullpath))
{
System.IO.Directory.CreateDirectory (Extractfullpath);
}
int ret = Unlha (0, String. Format ("x \" {0}\ "\" {1}\ "", Archivefile, Extractfullpath), NULL, 0);
if (ret!= 0)
{
if (ret = 32800)
{
throw new Exception ("File decompression cancellation");
}
Else
{
throw new Exception ("File decompression abnormal end");
}
}
Else
{
if (isdeletefile)
{
System.IO.File.Delete (Archivefile);
}
return true;
}
}
}
The project needs to extract this type of file, do not know, the Internet to see the data found is a common Japanese compression algorithm,
Look up a lot of information, there is no good solution to the package,
Later found this DLL can unpack the
But the code on the Web is VB or C.
Only a C # version of itself, in fact, even if C # calls the dynamic link library
Download the DLL first, and then put the DLL in the C:\Windows\System32 directory