Ticket #494: Some_WinAPI_ResourceFunctions.au3

File Some_WinAPI_ResourceFunctions.au3, 11.6 KB (added by smashly, on Aug 5, 2008 at 6:19:00 AM)

Some_WinAPI_ResourceFunctions.au3

Line 
1#AutoIt3Wrapper_Au3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
2
3#include <WinAPI.au3>
4
5Opt('MustDeclareVars', 1)
6
7; #FUNCTION# ====================================================================================================================
8; Name...........: _WinAPI_FindResource
9; Description ...: Determines the location of a resource with the specified type and name in the specified module.
10; Syntax.........: _WinAPI_FindResource($hInstance, $sResName, $iResType)
11; Parameters ....: $hInstance - Handle to the module whose executable file contains the resource.
12; $sResName - Specifies the string of the resource name to be loaded.
13; $iResType - Specifies the resource type:
14; $RT_CURSOR = 1
15; $RT_BITMAP = 2
16; $RT_ICON = 3
17; $RT_MENU = 4
18; $RT_DIALOG = 5
19; $RT_STRING = 6
20; $RT_FONTDIR = 7
21; $RT_FONT = 8
22; $RT_ACCELERATOR = 9
23; $RT_RCDATA = 10
24; $RT_MESSAGETABLE = 11
25; $RT_GROUP_CURSOR = 12
26; $RT_GROUP_ICON = 14
27; $RT_VERSION = 16
28; $RT_DLGINCLUDE = 17
29; $RT_PLUGPLAY = 19
30; $RT_VXD = 20
31; $RT_ANICURSOR = 21
32; $RT_ANIICON = 22
33; $RT_HTML = 23
34; $RT_MANIFEST = 24
35; Return values .: Success - Handle to the specified resource's information block.
36; Failure - Return 0 and set @error
37; @error 1 ~ 3 then it's a failed AutoIt DLLCall
38; @error 4 then it's the WinAPI error, @extended for _WinAPI_GetLastError().
39; Author ........: Smashly
40; Modified.......:
41; Remarks .......:
42; Related .......: _WinAPI_LoadLibrary, _WinAPI_LoadLibraryEx
43; Link ..........; @@MsdnLink@@ FindResourceA
44; Example .......;
45; ===============================================================================================================================
46Func _WinAPI_FindResource($hInstance, $sResName, $iResType)
47 Local $aResult, $sDec = "#"
48 If Not StringIsAlNum($sResName) Then $sDec = ""
49
50 $aResult = DllCall("kernel32.dll", "int", "FindResourceA", "hwnd", $hInstance, "str", $sDec & $sResName, "long", $iResType)
51 If @error Then Return SetError(@error, 0, 0)
52 If Not IsArray($aResult) Or $aResult[0] = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0)
53 Return SetError(0, 0, $aResult[0])
54EndFunc ;==>_WinAPI_FindResource
55
56; #FUNCTION# ====================================================================================================================
57; Name...........: _WinAPI_FindResourceEx
58; Description ...: Determines the location of the resource with the specified type, name, and language in the specified module.
59; Syntax.........: _WinAPI_FindResourceEx($hInstance, $sResName, $iResType, $iLangID)
60; Parameters ....: $hInstance - Handle to the module whose executable file contains the resource.
61; $sResName - Specifies the string of the resource name to be loaded.
62; $iResType - Specifies the resource type.
63; $RT_CURSOR = 1
64; $RT_BITMAP = 2
65; $RT_ICON = 3
66; $RT_MENU = 4
67; $RT_DIALOG = 5
68; $RT_STRING = 6
69; $RT_FONTDIR = 7
70; $RT_FONT = 8
71; $RT_ACCELERATOR = 9
72; $RT_RCDATA = 10
73; $RT_MESSAGETABLE = 11
74; $RT_GROUP_CURSOR = 12
75; $RT_GROUP_ICON = 14
76; $RT_VERSION = 16
77; $RT_DLGINCLUDE = 17
78; $RT_PLUGPLAY = 19
79; $RT_VXD = 20
80; $RT_ANICURSOR = 21
81; $RT_ANIICON = 22
82; $RT_HTML = 23
83; $RT_MANIFEST = 24
84; $iResLang - Specifies the language of the resource.
85; Return values .: Success - Handle to the specified resource's information block..
86; Failure - Return 0 and set @error
87; @error 1 ~ 3 then it's a failed AutoIt DLLCall
88; @error 4 then it's the WinAPI error, @extended for _WinAPI_GetLastError().
89; Author ........: Smashly
90; Modified.......:
91; Remarks .......:
92; Related .......: _WinAPI_LoadLibrary, _WinAPI_LoadLibraryEx
93; Link ..........; @@MsdnLink@@ FindResourceExA
94; Example .......;
95; ===============================================================================================================================
96Func _WinAPI_FindResourceEx($hInstance, $sResName, $iResType, $iResLang)
97 Local $aResult
98
99 $aResult = DllCall("kernel32.dll", "int", "FindResourceExA", "hwnd", $hInstance, "long", $iResType, "str", $sResName, "short", $iResLang)
100 If @error Then Return SetError(@error, 0, 0)
101 If Not IsArray($aResult) Or $aResult[0] = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0)
102 Return SetError(0, 0, $aResult[0])
103EndFunc ;==>_WinAPI_FindResourceEx
104
105; #FUNCTION# ====================================================================================================================
106; Name...........: _WinAPI_SizeOfResource
107; Description ...: Returns the size, in bytes, of the specified resource.
108; Syntax.........: _WinAPI_SizeOfResource($hInstance, $hFindRes)
109; Parameters ....: $hInstance - Handle to the module whose executable file contains the resource.
110; $hFindRes - Handle to the resource as returned from _WinAPI_FindResource or _WinAPI_FindResourceEx function.
111; Return values .: Success - The number of bytes in the resource.
112; Failure - Return 0 and set @error
113; @error 1 ~ 3 then it's a failed AutoIt DLLCall.
114; @error 4 then it's the WinAPI error, @extended for _WinAPI_GetLastError().
115; Author ........: Smashly
116; Modified.......:
117; Remarks .......:
118; Related .......: _WinAPI_FindResource, _WinAPI_FindResourceEx
119; Link ..........; @@MsdnLink@@ SizeofResource
120; Example .......;
121; ===============================================================================================================================
122Func _WinAPI_SizeOfResource($hInstance, $hFindRes)
123 Local $aResult
124
125 $aResult = DllCall("kernel32.dll", "dword", "SizeofResource", "hwnd", $hInstance, "hwnd", $hFindRes)
126 If @error Then Return SetError(@error, 0, 0)
127 If Not IsArray($aResult) Or $aResult[0] = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0)
128 Return SetError(0, 0, $aResult[0])
129EndFunc ;==>_WinAPI_SizeOfResource
130
131; #FUNCTION# ====================================================================================================================
132; Name...........: _WinAPI_LoadResource
133; Description ...: Loads the specified resource into global memory.
134; Syntax.........: _WinAPI_LoadResource($hInstance, $hFindRes)
135; Parameters ....: $hInstance - Handle to the module whose executable file contains the resource.
136; $hFindRes - Handle to the resource as returned from _WinAPI_FindResource or _WinAPI_FindResourceEx function.
137; Return values .: Success - Handle to the data associated with the resource.
138; Failure - Return 0 and set @error
139; @error 1 ~ 3 then it's a failed AutoIt DLLCall.
140; @error 4 then it's the WinAPI error, @extended for _WinAPI_GetLastError().
141; Author ........: Smashly
142; Modified.......:
143; Remarks .......:
144; Related .......: _WinAPI_FindResource, _WinAPI_FindResourceEx, _WinAPI_FreeResource
145; Link ..........; @@MsdnLink@@ LoadResource
146; Example .......;
147; ===============================================================================================================================
148Func _WinAPI_LoadResource($hInstance, $hFindRes)
149 Local $aResult
150
151 $aResult = DllCall("kernel32.dll", "int", "LoadResource", "hwnd", $hInstance, "hwnd", $hFindRes)
152 If @error Then Return SetError(@error, 0, 0)
153 If Not IsArray($aResult) Or $aResult[0] = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0)
154 Return SetError(0, 0, $aResult[0])
155EndFunc ;==>_WinAPI_LoadResource
156
157; #FUNCTION# ====================================================================================================================
158; Name...........: _WinAPI_LockResource
159; Description ...: Locks the specified resource in memory.
160; Syntax.........: _WinAPI_LockResource($hLoadRes)
161; Parameters ....: $hLoadRes - Handle to the resource to be locked as returned from _WinAPI_LoadResource function.
162; Return values .: Success - Handle to the data associated with the resource.
163; Failure - Return 0 and set @error
164; @error 1 ~ 3 then it's a failed AutoIt DLLCall.
165; @error 4 then it's the WinAPI error, @extended for _WinAPI_GetLastError().
166; Author ........: Smashly
167; Modified.......:
168; Remarks .......:
169; Related .......: _WinAPI_LoadResource
170; Link ..........; @@MsdnLink@@ LockResource
171; Example .......;
172; ===============================================================================================================================
173Func _WinAPI_LockResource($hLoadRes)
174 Local $aResult
175
176 $aResult = DllCall("kernel32.dll", "int", "LockResource", "hwnd", $hLoadRes)
177 If @error Then Return SetError(@error, 0, 0)
178 If Not IsArray($aResult) Or $aResult[0] = 0 Then Return SetError(4, _WinAPI_GetLastError(), 0)
179 Return SetError(0, 0, $aResult[0])
180EndFunc ;==>_WinAPI_LockResource
181
182
183; #FUNCTION# ====================================================================================================================
184; Name...........: _WinAPI_FreeResource
185; Description ...: Decrements (decreases by one) the reference count of a loaded resource.
186; Syntax.........: _WinAPI_FreeResource($hLoadRes)
187; Parameters ....: $hLoadRes - Handle of the resource to be freed as returned from _WinAPI_LoadResource.
188; Return values .: Success - Return 1
189; Failure - Return 0 and set @error
190; @error 1 ~ 3 then it's a failed AutoIt DLLCall
191; @error 4 then the resource was not freed, @extended for the return value of the call.
192; Author ........: Smashly
193; Modified.......:
194; Remarks .......:
195; Related .......: _WinAPI_LoadResource
196; Link ..........; @@MsdnLink@@ FreeResource
197; Example .......;
198; ===============================================================================================================================
199Func _WinAPI_FreeResource($hLoadRes)
200 Local $aResult
201
202 $aResult = DllCall("kernel32.dll", "int", "FreeResource", "hwnd", $hLoadRes)
203 If @error Then Return SetError(1, @error, 0)
204 If Not IsArray($aResult) Or $aResult[0] <> 0 Then SetError(4, $aResult[0], 0)
205 Return SetError(0, 0, 1)
206EndFunc ;==>_WinAPI_FreeResource