[PR]

『新妻LOVELY×CATION』を応援しています!
水無瀬の部屋 > Programming > sample > exe2ico > rsrc2ico.cpp
最終更新日: 2007/03/24

   1: //*********************************************************
   2: // プロジェクト: getico
   3: //  ファイル名: rsrc2ico.cpp
   4: //*********************************************************
   5: #include "rsrc2ico.h"
   6: #include "util.h"
   7: #include <filefmt/icofile.h>
   8: 
   9: 
  10: //---------------------------------------------------------
  11: // ファイルスコープ関数 の 宣言
  12: //---------------------------------------------------------
  13: static size_t put_ifh(   BYTE *buf, size_t bufsize, size_t offset, const ICONFILEHEAD *ifh );
  14: static size_t put_iih(   BYTE *buf, size_t bufsize, size_t offset, const ICONRESINF *iri, size_t img_offset );
  15: static size_t put_img(   BYTE *buf, size_t bufsize, size_t offset, HMODULE hModule, const char *id, size_t size );
  16: static size_t put_icons( BYTE *buf, size_t bufsize, size_t offset, const ICONRESINF *iri, int num, HMODULE hModule );
  17: static size_t put_icon(  BYTE *buf, size_t bufsize, size_t iih_offset, size_t img_offset, const ICONRESINF *iri, HMODULE hModule );
  18: 
  19: 
  20: //*********************************************************
  21: // rsrc2ico
  22: //*********************************************************
  23: size_t
  24: CALLBACK
  25: rsrc2ico
  26: 	(
  27: 		      BYTE    *buf,
  28: 		      size_t   bufsize,
  29: 		      HMODULE  hModule,
  30: 		const char    *name,
  31: 		const char    *type
  32: 	)
  33: {
  34: 	// パラメタの仮定
  35: 	ASSERT( IsValidInstanceHandle( hModule ) );
  36: 	ASSERT( IsValidResourceName( name ) );
  37: 	ASSERT( IsValidResourceName( type ) );
  38: 	ASSERT(  buf || (0 == bufsize) );
  39: 	ASSERT( !buf || IsValidPtr( buf, bufsize ) );
  40: 	ASSERT( !buf || (DESTROY_BUFFER( buf, bufsize ), true) ); // [破壊]
  41: 
  42: 	//
  43: 	size_t size = 0;
  44: 
  45: 	//
  46: 	const void *src = GetResourcePtr( hModule, name, type );
  47: 	if ( src )
  48: 	{
  49: 		// 
  50: 		const ICONFILEHEAD *ifh = static_cast<const ICONFILEHEAD *>( src );
  51: 		size += put_ifh( buf, bufsize, size, ifh++ );
  52: 
  53: 		//
  54: 		const ICONRESINF *iri = static_cast<const ICONRESINF *>( static_cast<const void *>( ifh ) );
  55: 		size += put_icons( buf, bufsize, size, iri, ifh->num, hModule );
  56: 	}
  57: 
  58: 	ASSERT( !buf || (size <= bufsize) );
  59: 	ASSERT( !buf
  60: 		|| (size    == rsrc2ico( null, 0, hModule, name, type ))
  61: 		|| (bufsize <= rsrc2ico( null, 0, hModule, name, type )) );
  62: 	return size;
  63: }//rsrc2ico
  64: 
  65: 
  66: //******************************************************************************************************************
  67: // private
  68: //******************************************************************************************************************
  69: //*********************************************************
  70: // put_ifh
  71: //*********************************************************
  72: static
  73: size_t
  74: put_ifh
  75: 	(
  76: 		      BYTE         *buf,
  77: 		      size_t        bufsize,
  78: 		      size_t        offset,
  79: 		const ICONFILEHEAD *ifh
  80: 	)
  81: {
  82: 	// パラメタの仮定
  83: 	ASSERT(  buf || (0 == bufsize) );
  84: 	ASSERT( !buf || (offset < bufsize) );
  85: 	ASSERT( !buf || IsValidPtr( buf, bufsize ) );
  86: 	ASSERT( IsValidReadPtr( ifh, sizeof( *ifh ) ) );
  87: 
  88: 	//
  89: 	const size_t size = sizeof( *ifh );
  90: 
  91: 	//
  92: 	if ( buf )
  93: 	{
  94: 		memmove( buf + offset, ifh, size );
  95: 	}
  96: 
  97: 	ASSERT( !buf || (offset + size <= bufsize) );
  98: 	ASSERT( !buf
  99: 		|| (size    ==          put_ifh( null, 0, offset, ifh ))
 100: 		|| (bufsize <= offset + put_ifh( null, 0, offset, ifh )) );
 101: 	return size;
 102: }//put_ifh
 103: 
 104: //*********************************************************
 105: // put_icons
 106: //*********************************************************
 107: static
 108: size_t
 109: put_icons
 110: 	(
 111: 		      BYTE       *buf,
 112: 		      size_t      bufsize,
 113: 		      size_t      offset,
 114: 		const ICONRESINF *iri,
 115: 		      int         num,
 116: 		      HMODULE     hModule
 117: 	)
 118: {
 119: 	// パラメタの仮定
 120: 	ASSERT( 0 < num );
 121: 	ASSERT( IsValidReadPtr( iri, num * sizeof( *iri ) ) );
 122: 	ASSERT( IsValidInstanceHandle( hModule ) );
 123: 	ASSERT(  buf || (0 == bufsize) );
 124: 	ASSERT( !buf || (offset < bufsize) );
 125: 	ASSERT( !buf || IsValidPtr( buf, bufsize ) );
 126: 
 127: 	//
 128: 	size_t size = (num * sizeof( ICONINFOHEAD ));
 129: 
 130: 	//
 131: 	{for( int i = 0; i < num; ++i )
 132: 	{
 133: 		size += put_icon( buf, bufsize, offset + (i * sizeof( ICONINFOHEAD )), offset + size, &iri[ i ], hModule );
 134: 	}}
 135: 
 136: 	ASSERT( !buf || (offset + size <= bufsize) );
 137: 	ASSERT( !buf
 138: 		|| (size    ==          put_icons( null, 0, offset, iri, num, hModule ))
 139: 		|| (bufsize <= offset + put_icons( null, 0, offset, iri, num, hModule )) );
 140: 	return size;
 141: }//put_icons
 142: 
 143: //*********************************************************
 144: // put_icon
 145: //*********************************************************
 146: static
 147: size_t
 148: put_icon
 149: 	(
 150: 		      BYTE       *buf,
 151: 		      size_t      bufsize,
 152: 		      size_t      iih_offset,
 153: 		      size_t      img_offset,
 154: 		const ICONRESINF *iri,
 155: 		      HMODULE     hModule
 156: 	)
 157: {
 158: 	// パラメタの仮定
 159: 	ASSERT( iih_offset < img_offset );
 160: 	ASSERT( IsValidReadPtr( iri, sizeof( *iri ) ) );
 161: 	ASSERT( IsValidInstanceHandle( hModule ) );
 162: 	ASSERT(  buf || (0 == bufsize) );
 163: 	ASSERT( !buf || (iih_offset < bufsize) );
 164: 	ASSERT( !buf || (img_offset < bufsize) );
 165: 	ASSERT( !buf || IsValidPtr( buf, bufsize ) );
 166: 
 167: 
 168: 	put_iih( buf, bufsize, iih_offset, iri, img_offset );
 169: 	const size_t size = put_img( buf, bufsize, img_offset, hModule, MAKEINTRESOURCE( iri->wID ), iri->size );
 170: 
 171: 	ASSERT( !buf || (img_offset + size <= bufsize) );
 172: 	ASSERT( !buf
 173: 		|| (size    ==              put_icon( null, 0, iih_offset, img_offset, iri, hModule ))
 174: 		|| (bufsize <= img_offset + put_icon( null, 0, iih_offset, img_offset, iri, hModule )) );
 175: 	return size;
 176: }//put_icon
 177: 
 178: //*********************************************************
 179: // put_iih
 180: //*********************************************************
 181: static
 182: size_t
 183: put_iih
 184: 	(
 185: 		      BYTE       *buf,
 186: 		      size_t      bufsize,
 187: 		      size_t      offset,
 188: 		const ICONRESINF *iri,
 189: 		      size_t      img_offset
 190: 	)
 191: {
 192: 	// パラメタの仮定
 193: 	ASSERT(  buf || (0 == bufsize) );
 194: 	ASSERT( !buf || (offset < bufsize) );
 195: 	ASSERT( !buf || IsValidPtr( buf, bufsize ) );
 196: 	ASSERT( IsValidReadPtr( iri, sizeof( *iri ) ) );
 197: 	
 198: 	//
 199: 	const size_t size = sizeof( ICONINFOHEAD );
 200: 
 201: 	//
 202: 	if ( buf )
 203: 	{
 204: 		ICONINFOHEAD *iih = static_cast<ICONINFOHEAD *>( static_cast<void *>( buf + offset ) );
 205: 		iih->width   = iri->width;
 206: 		iih->height  = iri->height;
 207: 		iih->color   = iri->color;
 208: 		iih->unknown = iri->unknown;
 209: 		iih->planes  = iri->planes;
 210: 		iih->bits    = iri->bits;
 211: 		iih->size    = iri->size;
 212: 		iih->offset  = _w64_static_cast<DWORD>( img_offset );
 213: 	}
 214: 
 215: 	ASSERT( !buf || (offset + size <= bufsize) );
 216: 	ASSERT( !buf
 217: 		|| (size    ==          put_iih( null, 0, offset, iri, img_offset ))
 218: 		|| (bufsize <= offset + put_iih( null, 0, offset, iri, img_offset )) );
 219: 	return size;
 220: }//put_iih
 221: 
 222: //*********************************************************
 223: // put_img
 224: //*********************************************************
 225: static
 226: size_t
 227: put_img
 228: 	(
 229: 		      BYTE    *buf,
 230: 		      size_t   bufsize,
 231: 		      size_t   offset,
 232: 		      HMODULE  hModule,
 233: 		const char    *name,
 234: 		      size_t   size
 235: 	)
 236: {
 237: 	// パラメタの仮定
 238: 	ASSERT( IsValidInstanceHandle( hModule ) );
 239: 	ASSERT( IsValidResourceName( name ) );
 240: 	ASSERT(  buf || (0 == bufsize) );
 241: 	ASSERT( !buf || ((offset + size) <= bufsize) );
 242: 	ASSERT( !buf || IsValidPtr( buf, bufsize ) );
 243: 
 244: 	const void *img = GetResourcePtr( hModule, name, RT_ICON );
 245: 	if ( img )
 246: 	{
 247: 		if ( buf )
 248: 		{
 249: 			memmove( buf + offset, img, size );
 250: 		}
 251: 	}
 252: 
 253: 	ASSERT( !buf || (offset + size <= bufsize) );
 254: 	ASSERT( !buf
 255: 		|| (size    ==          put_img( null, 0, offset, hModule, name, size ))
 256: 		|| (bufsize <= offset + put_img( null, 0, offset, hModule, name, size )) );
 257: 	return size;
 258: }//put_img
 259: 
 260: 
 261: //** end **

参照:


Google
ご意見・ご感想をお聞かせ下さい。匿名で送信できます。

 * 返信が必要な場合には postmaster@katsura-kotonoha.sakura.ne.jp へ直接メールしてください。

水無瀬の部屋 > sample > exe2ico > rsrc2ico.cpp

このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/exe2ico/rsrc2ico_cpp.shtml
『新妻LOVELY×CATION』を応援しています!