水無瀬の部屋 > Programming > sample > exe2ico > exe2rsrc.cpp |
---|
1: //*********************************************************
2: // プロジェクト: exe2ico
3: // ファイル名: exe2rsrc.cpp
4: //*********************************************************
5: #include "exe2rsrc.h"
6: #include "util.h"
7:
8:
9: //---------------------------------------------------------
10: // 構造体 の 宣言
11: //---------------------------------------------------------
12: // ENUMRESOURCENAMEPARAM_t
13: typedef struct ENUMRESOURCENAMEPARAM_tag
14: {
15: int index;
16: const char *type;
17: const char *ext;
18: const char *rsrcfile;
19: rsrc2file_t rsrc2file;
20: } ENUMRESOURCENAMEPARAM_t;
21:
22:
23: //---------------------------------------------------------
24: // ファイルスコープ関数 の 宣言
25: //---------------------------------------------------------
26: static BOOL CALLBACK EnumResourceNameProc( HMODULE hModule, const char *szResourceType, char *szResourceName, LONG_PTR lParam );
27:
28:
29: //*********************************************************
30: // exe2rsrc
31: //*********************************************************
32: bool
33: exe2rsrc
34: (
35: const char *filename,
36: const char *type,
37: const char *ext,
38: rsrc2file_t rsrc2file
39: )
40: {
41: // パラメタの仮定
42: ASSERT( IsPathFile( filename ) );
43: ASSERT( IsValidResourceName( type ) );
44: ASSERT( IsValidLocalPathString( ext ) );
45: ASSERT( IsValidCodePtr( rsrc2file ) );
46:
47: HMODULE hFile = LoadLibraryEx( filename, null, LOAD_LIBRARY_AS_DATAFILE | LOAD_WITH_ALTERED_SEARCH_PATH );
48: if ( !hFile )
49: {
50: return false;
51: }
52:
53: ENUMRESOURCENAMEPARAM_t ernp;
54: memzero( &ernp, sizeof( ernp ) );
55: ernp.rsrcfile = filename;
56: ernp.ext = ext;
57: ernp.type = type;
58: ernp.index = 0;
59: ernp.rsrc2file = rsrc2file;
60: EnumResourceNames
61: (
62: hFile,
63: type,
64: EnumResourceNameProc,
65: reinterpret_cast<LONG_PTR>( &ernp )
66: );
67: VERIFY( FreeLibrary( hFile ) );
68:
69: return true;
70: }//exe2rsrc
71:
72:
73: //******************************************************************************************************************
74: // private
75: //******************************************************************************************************************
76: //*********************************************************
77: // EnumResourceNameProc
78: // false を返すと列挙が中止される
79: //*********************************************************
80: static
81: BOOL
82: CALLBACK
83: EnumResourceNameProc
84: (
85: HMODULE hModule,
86: const char *,
87: char *name,
88: LONG_PTR lParam
89: )
90: {
91: // パラメタの仮定
92: ASSERT( IsValidInstanceHandle( hModule ) );
93: ASSERT( IsValidResourceName( name ) );
94: ASSERT( IsValidPtr( (ENUMRESOURCENAMEPARAM_t *)lParam, sizeof(ENUMRESOURCENAMEPARAM_t) ) );
95:
96: //
97: ENUMRESOURCENAMEPARAM_t *ernp = reinterpret_cast<ENUMRESOURCENAMEPARAM_t *>( lParam );
98: ASSERT( IsPathFile( ernp->rsrcfile ) );
99: ASSERT( IsValidResourceName( ernp->type ) );
100: ASSERT( IsValidLocalPathString( ernp->ext ) );
101: ASSERT( IsValidCodePtr( ernp->rsrc2file ) );
102:
103: //
104: const int index = ernp->index++;
105:
106: //
107: const size_t bufsize = ernp->rsrc2file( null, 0, hModule, name, ernp->type );
108: if ( 0 < bufsize )
109: {
110: BYTE *rsrc = (BYTE *)malloc( bufsize );
111: if ( rsrc )
112: {
113: const size_t size = ernp->rsrc2file( rsrc, bufsize, hModule, name, ernp->type );
114: if ( size == bufsize )
115: {
116: OutputResourceFile( rsrc, size, ernp->rsrcfile, ernp->ext, index );
117: }
118: free( rsrc );
119: }
120: }
121: return true;
122: }//EnumResourceNameProc
123:
124:
125: //** end **
126:
127:
128:
参照:
水無瀬の部屋 > sample > exe2ico > exe2rsrc.cpp |
---|
このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/exe2ico/exe2rsrc_cpp.shtml