[C#] Bestand in LHA/LZH lezen met UNLHA32.DLL

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Tanuki
  • Registratie: Januari 2005
  • Niet online
Ik wil graag bepaalde bestanden uit een lzh/lha archief inlezen in mijn C# programma.

Ik heb al een aardige class:
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    public class Cmarc
    {
        public const int FNAME_MAX32 = 512;

        [Flags]
        public enum CheckMode : int
        {
            Rapid = 0,
            Basic = 1,
            FullCrc = 2,
            Recovery = 4,
            Sfx = 8,
            All = 16
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct Time
        {
            public UInt32 ft_tsec; /* Two second interval */
            public UInt32 ft_min; /* Minutes */
            public UInt32 ft_hour;  /* Hours */
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct IndividualInfo
        {
            public UInt32 dwOriginalSize;
            public UInt32 dwCompressedSize;
            public UInt32 dwCRC;
            public UInt32 uFlag;
            public UInt32 uOSType;
            public UInt16 wRatio;
            public UInt16 wDate;
            public UInt16 wTime;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FNAME_MAX32 + 1)]
            public string szFileName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
            public string dummy1;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
            public string szAttribute;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
            public string szMode;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct ExtractingInfo
        {
            UInt32 DwFileSize;
            UInt32 DwWriteSize;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FNAME_MAX32 + 1)]
            public string SzSourceFileName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
            public string Dummy1;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = FNAME_MAX32 + 1)]
            public string SzDestFileName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
            public string Dummy;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct ExtractingInfoEx
        {
            ExtractingInfo ExInfo;
            UInt32 DwCompressedSize;
            UInt32 DwCRC;
            UInt32 UOSType;
            UInt32 WRatio;
            UInt16 WDate;
            UInt16 WTime;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
            public string SzAttribute;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]
            public string SzMode;
        }

        public delegate UInt16 GetVersionDelegate();
        public GetVersionDelegate GetVersion;

        public delegate UInt16 GetSubVersionDelegate();
        public GetSubVersionDelegate GetSubVersion;

        public delegate bool GetRunningDelegate();
        public GetRunningDelegate GetRunning;

        public delegate bool GetBackGroundModeDelegate();
        public GetBackGroundModeDelegate GetBackGroundMode;

        public delegate bool SetBackGroundModeDelegate(bool _bBackGroundMode);
        public SetBackGroundModeDelegate SetBackGroundMode;

        public delegate bool GetCursorModeDelegate();
        public GetCursorModeDelegate GetCursorMode;

        public delegate bool SetCursorModeDelegate(bool _CursorMode);
        public SetCursorModeDelegate SetCursorMode;

        public delegate bool GetCursorIntervalDelegate();
        public GetCursorIntervalDelegate GetCursorInterval;

        public delegate bool SetCursorIntervalDelegate(UInt16 _Interval);
        public SetCursorIntervalDelegate SetCursorInterval;

        public delegate bool CheckArchiveDelegate([MarshalAs(UnmanagedType.LPStr)]string _szFileName, CheckMode _iMode);
        public CheckArchiveDelegate CheckArchive;

        public delegate Int32 GetFileCountDelegate([MarshalAs(UnmanagedType.LPStr)]string _szArcFile);
        public GetFileCountDelegate GetFileCount;

        public delegate bool QueryFunctionListDelegate(Int32 _iFunction);
        public QueryFunctionListDelegate QueryFunctionList;

        public delegate IntPtr OpenArchiveDelegate(IntPtr _hwnd, string _szFileName, UInt32 _dwMode);
        public OpenArchiveDelegate OpenArchive;

        public delegate Int32 CloseArchiveDelegate(IntPtr _harc);
        public CloseArchiveDelegate CloseArchive;

        public delegate Int32 FindFirstDelegate(IntPtr _harc, string _szWildName, ref IndividualInfo lpSubInfo);
        public FindFirstDelegate FindFirst;

        public delegate Int32 FindNextDelegate(IntPtr _harc, ref IndividualInfo lpSubInfo);
        public FindNextDelegate FindNext;

        public delegate Int32 GetFileNameDelegate(IntPtr _harc, StringBuilder _lpBuffer, int _nsize);
        public GetFileNameDelegate GetFileName;

        public delegate Int32 ExtractMemDelegate(IntPtr _hwnd, [MarshalAs(UnmanagedType.LPStr)]string _szCmdLine, byte[] _szBuffer, UInt32 _dwSize, ref Time _lpTime, UInt32[] _lpwAttr, UInt16[] _lpdwWriteSize);
        public ExtractMemDelegate ExtractMem;

        public IntPtr handle = IntPtr.Zero;

        public Cmarc(string dll)
        {
            IntPtr dllHandle = Win32Api.LoadLibrary(dll + ".dll");
            if (dllHandle == IntPtr.Zero)
            {
                throw new ArgumentException("Cannot load DLL " + dll + ".dll", "dll");
            }

            // Register DLL functions using the specified delegates
            GetVersion = Win32Api.GetDelegateForFunctionPointer<GetVersionDelegate>(dllHandle, dll + "GetVersion");
            GetSubVersion = Win32Api.GetDelegateForFunctionPointer<GetSubVersionDelegate>(dllHandle, dll + "GetSubVersion");
            GetRunning = Win32Api.GetDelegateForFunctionPointer<GetRunningDelegate>(dllHandle, dll + "GetRunning");
            GetBackGroundMode = Win32Api.GetDelegateForFunctionPointer<GetBackGroundModeDelegate>(dllHandle, dll + "GetBackGroundMode");
            SetBackGroundMode = Win32Api.GetDelegateForFunctionPointer<SetBackGroundModeDelegate>(dllHandle, dll + "SetBackGroundMode");
            GetCursorMode = Win32Api.GetDelegateForFunctionPointer<GetCursorModeDelegate>(dllHandle, dll + "GetCursorMode");
            SetCursorMode = Win32Api.GetDelegateForFunctionPointer<SetCursorModeDelegate>(dllHandle, dll + "SetCursorMode");
            GetCursorInterval = Win32Api.GetDelegateForFunctionPointer<GetCursorIntervalDelegate>(dllHandle, dll + "GetCursorInterval");
            SetCursorInterval = Win32Api.GetDelegateForFunctionPointer<SetCursorIntervalDelegate>(dllHandle, dll + "SetCursorInterval");
            CheckArchive = Win32Api.GetDelegateForFunctionPointer<CheckArchiveDelegate>(dllHandle, dll + "CheckArchive");
            GetFileCount = Win32Api.GetDelegateForFunctionPointer<GetFileCountDelegate>(dllHandle, dll + "GetFileCount");
            QueryFunctionList = Win32Api.GetDelegateForFunctionPointer<QueryFunctionListDelegate>(dllHandle, dll + "QueryFunctionList");
            OpenArchive = Win32Api.GetDelegateForFunctionPointer<OpenArchiveDelegate>(dllHandle, dll + "OpenArchive");
            CloseArchive = Win32Api.GetDelegateForFunctionPointer<CloseArchiveDelegate>(dllHandle, dll + "CloseArchive");

            FindFirst = Win32Api.GetDelegateForFunctionPointer<FindFirstDelegate>(dllHandle, dll + "FindFirst");
            FindNext = Win32Api.GetDelegateForFunctionPointer<FindNextDelegate>(dllHandle, dll + "FindNext");
            GetFileName = Win32Api.GetDelegateForFunctionPointer<GetFileNameDelegate>(dllHandle, dll + "GetFileName");
            ExtractMem = Win32Api.GetDelegateForFunctionPointer<ExtractMemDelegate>(dllHandle, dll + "ExtractMem");
            //CompressMem = Win32Api.GetDelegateForFunctionPointer<CompressMem>(dllHandle, dll + "CompressMem");
        }
    }


Nu is het probleem alleen dat ik niet weet hoe ik ExtractMem moet aanroepen, ik weet eigenlijk ook niet zeker of ik hem wel goed gespecificeerd heb.

Ik kan wel een archief openen, lijst met bestanden + verdere informatie (datetime/crc/etc) terug krijgen. Da's allemaal geen probleem.

De parameter die ik meegeef aan de class is trouwens "Unlha", de prefix voor de Unlha32 functies. De DLL heet Unlha.dll, dus dat gaat ook allemaal goed.

Het enige dat ik tot mijn beschikking heb is een (redelijke brakke) vertaalde versie van de originele Japanse API omschrijving:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-------------------------------------------------- ---------------------
% O int WINAPI UnlhaExtractMem (const HWND _hwnd, LPCSTR _szCmdLine,
LPBYTE _szBuffer, const DWORD _dwSize, time_t * _lpTime,
LPWORD _lpwAttr, LPDWORD _lpdwWriteSize)
-------------------------------------------------- ---------------------
Order 49
Features
To expand the memory buffer. Unfortunately, _lpdwWriteSize specified
Process multiple times for each size you use ... and can not be performed.

Arguments
_hwnd UNLHA32.DLL apps window handle calls.
UNLHA32.DLL this window when you run against EnableWin-
dow () suppresses the action of running windows. Window
If the console application or does not exist, you must provide a
If not, pass NULL.
_szCmdLine UNLHA32.DLL command string to pass. Unlha () same
Can be specified, the command will be ignored.
_lpBuffer buffer to store the expanded image. Buffer specified here
For, _dwSize must guarantee that the size indicated by
Is required.
_dwSize buffer size. UNLHA32.DLL finger than the size of results returned
If the specified size is small to the size specified is printed.
_lpTime the extracted files in the UTC timestamp get.
Specify NULL if you do not need it.
_lpwAttr get the file attributes expanded. NULL if not needed
Specified.
_lpdwWriteSize
Get a written result of expansion size. If you do not need
Specify NULL.

Return value
0:00 a success.
The number of non-zero error occurs.

Other
The nature of the API, the use of the archive, or file name wildcards think irrelevant
Waremasu.

-------------------------------------------------- ---------------------
% P int WINAPI UnlhaCompressMem (const HWND _hwnd, LPCSTR _szCmdLine,
const LPBYTE _szBuffer, const DWORD _dwSize,
const time_t * _lpTime, const LPWORD _lpwAttr,
LPDWORD _lpdwWriteSize)
-------------------------------------------------- ---------------------
Order Number 50
Features
Stored in the archive to compress the contents of the memory buffer. Unfortunately, the memory
It does not create an archive is not over. (^^;)

Arguments
_hwnd UNLHA32.DLL apps window handle calls.
UNLHA32.DLL this window when you run against EnableWin-
dow () suppresses the action of running windows. Window
If the console application or does not exist, you must provide a
If not, pass NULL.
_szCmdLine UNLHA32.DLL command string to pass. Specify a file name
What is the name of the store when you specify.
_lpBuffer buffer containing the image to compress.
_dwSize image size.
_lpTime the time specified in the UTC store. NULL to specify and store
We will use the current time.
Specify the attribute that stores _lpwAttr. If you specify NULL and FA_ARCH
Will be considered.
_lpdwWriteSize
Get a reduction in size. Specify NULL if not needed
The.

Return value
0:00 a success.
The number of non-zero error occurs.

Other
The nature of the API, the use of the archive or file name wildcards think irrelevant
Waremasu.


Het zou wel mogelijk moeten zijn, maar het lukt gewoon niet. Ik krijg een vage popup van UNLHA32.DLL dat ie al in gebruik is.

Is er misschien iemand die hier ietsje meer verstand van heeft en mij zou kunnen vertellen waar ik de fout zou kunnen zoeken? En is er iemand die mij kan vertellen of ik de vertaling van de functie signatuur van C naar C# goed heb gedaan?

PV: Growatt MOD5000TL3-XH + 5720wp, WPB: Atlantic Explorer v4 270LC, L/L: MHI SCM 125ZM-S + SRK 50ZS-W + 2x SRK 25ZS-W + SRK 20ZS-W Modbus kWh meter nodig?


Acties:
  • 0 Henk 'm!

  • farlane
  • Registratie: Maart 2000
  • Laatst online: 16-09 22:43
Geen tip van mij hier maar ehm als ik deze code zie schreeuwt het eigenlijk gewoon om C.

Somniferous whisperings of scarlet fields. Sleep calling me and in my dreams i wander. My reality is abandoned (I traverse afar). Not a care if I never everwake.


Acties:
  • 0 Henk 'm!

  • Soultaker
  • Registratie: September 2000
  • Laatst online: 03:13
l0c4lh0st schreef op zaterdag 19 februari 2011 @ 21:02:
En is er iemand die mij kan vertellen of ik de vertaling van de functie signatuur van C naar C# goed heb gedaan?
Ik weet het ook niet precies. Waar baseer je deze mapping op? In het bijzonder de array argumenten vind ik dubieus; ik zou denken dat arrays in C# ingewikkelder zijn dan een simpele sequentie van elementen die ze zin C zijn, dus daar heb je waarschijnlijk een andere declaratie voor nodig.

Verder zijn HWNDs en HANDLEs in Win32 void-pointers, niet int-pointers (maar dat maakt praktisch gezien misschien niet uit). Verder lijk je words en doublewords omgedraaid te hebben; words zijn 16-bits integers, doublewords 32-bits integers. Bovendien zie ik je wederom arrays gebruiken als pointers; werkt dat echt zo? Is er geen native pointer type?

Acties:
  • 0 Henk 'm!

  • H!GHGuY
  • Registratie: December 2002
  • Niet online

H!GHGuY

Try and take over the world...

Kijk ook eens naar het DllImport Attribute. Al die delegates zijn voor zover ik weet bad bad practice.

ASSUME makes an ASS out of U and ME