01 /*
02 *<p>Description : Write Resource to File</p>
03 *<p>Author : fzy112001</p>
04 *@param : hModule, handle of Exe/Dll
05 *@param : lpName, name of the resource
06 *@param : lpType, resource type
07 *@param : szFile, dst file
08 *@throws : NULL
09 *@return : true, success
10 */
11 bool WriteCustomResource( HMODULE hModule, LPCTSTR lpName, LPCTSTR lpType, const char* szFile )
12 {
13 if( (NULL == lpName) || (NULL == lpType) || (NULL == szFile) )
14 {
15 return false;
16 }
17
18 HRSRC hRsrc = FindResource( hModule, lpName, lpType );
19 if( !hRsrc )
20 {
21 return false;
22 }
23
24 DWORD dwSize = SizeofResource( hModule, hRsrc );
25 if( !dwSize )
26 {
27 return false;
28 }
29
30 HGLOBAL hResource = LoadResource( hModule, hRsrc );
31 if( !hResource )
32 {
33 return false;
34 }
35
36 char *p = (char*)LockResource( hResource );
37 if( !p )
38 {
39 FreeResource( hResource );
40 return false;
41 }
42
43 FILE* fp = fopen( "C://a.bin", "w" );
44 if( !fp )
45 {
46 FreeResource( hResource );
47 return false;
48 }
49 fwrite( p, 1, dwSize, fp );
50 fclose( fp );
51
52 FreeResource( hResource );
53 return true;
54 }
02 *<p>Description : Write Resource to File</p>
03 *<p>Author : fzy112001</p>
04 *@param : hModule, handle of Exe/Dll
05 *@param : lpName, name of the resource
06 *@param : lpType, resource type
07 *@param : szFile, dst file
08 *@throws : NULL
09 *@return : true, success
10 */
11 bool WriteCustomResource( HMODULE hModule, LPCTSTR lpName, LPCTSTR lpType, const char* szFile )
12 {
13 if( (NULL == lpName) || (NULL == lpType) || (NULL == szFile) )
14 {
15 return false;
16 }
17
18 HRSRC hRsrc = FindResource( hModule, lpName, lpType );
19 if( !hRsrc )
20 {
21 return false;
22 }
23
24 DWORD dwSize = SizeofResource( hModule, hRsrc );
25 if( !dwSize )
26 {
27 return false;
28 }
29
30 HGLOBAL hResource = LoadResource( hModule, hRsrc );
31 if( !hResource )
32 {
33 return false;
34 }
35
36 char *p = (char*)LockResource( hResource );
37 if( !p )
38 {
39 FreeResource( hResource );
40 return false;
41 }
42
43 FILE* fp = fopen( "C://a.bin", "w" );
44 if( !fp )
45 {
46 FreeResource( hResource );
47 return false;
48 }
49 fwrite( p, 1, dwSize, fp );
50 fclose( fp );
51
52 FreeResource( hResource );
53 return true;
54 }