bool WdeDBI2Mem( WdeDialogBoxInfo *info, uint_8 **pdata, uint_32 *psize ) { bool ok; size_t size, memsize; LIST *l; WdeDialogBoxControl *ci; bool is32bit; bool is32bitEx; uint_8 *data; uint_8 *start; if( info == NULL || pdata == NULL || psize == NULL ) return( false ); start = NULL; is32bit = info->dialog_header->is32bit; is32bitEx = info->dialog_header->is32bitEx; memsize = WdeCalcSizeOfWdeDialogBoxInfo( info ); ok = (memsize != 0); if( ok ) { start = WRMemAlloc( memsize ); ok = (start != NULL); } if( ok ) { data = start; size = WdeDialogBoxHeaderToMem( info->dialog_header, data ); data += size; ok = (size != 0); } if( ok ) { for( l = info->control_list; l != NULL; l = ListNext( l ) ) { ci = ListElement( l ); if( ci == NULL ) { ok = false; break; } if( is32bit ) { PADDING_WRITE( data, start ); } size = WdeDialogBoxControlToMem( ci, data, is32bit, is32bitEx ); data += size; if( size == 0 ) { ok = false; break; } } } if( ok ) { if( is32bit ) { PADDING_WRITE( data, start ); } } *psize = 0; *pdata = NULL; if( ok ) { ok = (data - start == memsize); if( ok ) { *psize = memsize; *pdata = start; } } if( !ok && start != NULL ) { WRMemFree( start ); } return( ok ); }
Bool WdeDBI2Mem( WdeDialogBoxInfo *info, uint_8 **mem, uint_32 *size ) { Bool ok; uint_32 pos, memsize, sz, pad; LIST *l; WdeDialogBoxControl *ci; Bool is32bit; Bool is32bitEx; is32bit = info->dialog_header->is32bit; is32bitEx = info->dialog_header->is32bitEx; ok = ( info && mem && size ); if( ok ) { *mem = NULL; memsize = (int) WdeCalcSizeOfWdeDialogBoxInfo( info ); ok = ( memsize != 0 ); } if( ok ) { *mem = WdeMemAlloc( memsize ); ok = ( *mem != NULL ); } if( ok ) { if( is32bit && is32bitEx ) { pos = WdeDialogBoxExHeaderToMem( info->dialog_header, *mem ); } else { pos = WdeDialogBoxHeaderToMem( info->dialog_header, *mem ); } ok = ( pos != 0 ); } if( ok ) { for ( l = info->control_list; l; l = ListNext(l) ) { ci = ListElement ( l ); if( ci == NULL ) { ok = FALSE; break; } if( is32bit ) { pad = CALC_PAD( pos, sizeof(uint_32) ); memset( (*mem)+pos, 0, pad ); pos += pad; } sz = WdeDialogBoxControlToMem( ci, (*mem)+pos, is32bit, is32bitEx ); if( sz == 0 ) { ok = FALSE; break; } pos += sz; } } if( is32bit ) { pad = CALC_PAD( pos, sizeof(uint_32) ); memset( (*mem)+pos, 0, pad ); pos += pad; } if ( ok ) { ok = ( pos == memsize ); if ( ok ) { *size = memsize; } } else { if ( mem && *mem ) { WdeMemFree ( *mem ); *mem = NULL; } } return ( ok ); }