📄 wdei2mem.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <windows.h>
#include <string.h>
#include "list.def"
#include "wrdll.h"
#include "wrutil.h"
#include "wdeglbl.h"
#include "wdemem.h"
#include "wderesin.h"
#include "wdecsize.h"
#include "wde_wres.h"
#include "wrutil.h"
#include "wdei2mem.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
/****************************************************************************/
/* type definitions */
/****************************************************************************/
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
static WdeDialogBoxHeader *WdeMem2DialogBoxHeader ( uint_8 **data, Bool );
static WdeDialogBoxHeader *WdeMem2DialogBoxExHeader ( uint_8 **data );
static WdeDialogBoxControl *WdeMem2DialogBoxControl ( uint_8 **data, Bool, Bool );
static ResNameOrOrdinal *WdeMem2NameOrOrdinal ( uint_8 **data, Bool );
static ControlClass *WdeMem2ControlClass ( uint_8 **data, Bool );
static char *WdeMem2String ( uint_8 **data, Bool );
/****************************************************************************/
/* static variables */
/****************************************************************************/
static int WdeStringToMem( char *string, uint_8 use_unicode, uint_8 *mem )
{
int len;
uint_16 *data16;
if( !string ) {
string = "";
}
if( use_unicode ) {
len = 0;
if( WRmbcs2unicode( string, NULL, &len ) ) {
if( !WRmbcs2unicodeBuf( string, (char *)mem, len ) ) {
len = 0;
}
}
if( len == 0 ) {
data16 = (uint_16 *)mem;
data16[0] = 0;
len = 2;
}
} else {
len = strlen( string ) + 1;
memcpy( mem, string, len );
}
return( len );
}
static int WdeNameOrOrdToMem( ResNameOrOrdinal *name, uint_8 use_unicode,
uint_8 *mem )
{
int num;
uint_16 *data16;
if( !name ) {
num = WdeStringToMem( "", use_unicode, mem );
} else {
if( name->ord.fFlag == 0xff ) {
if( use_unicode ) {
data16 = (uint_16 *)mem;
data16[0] = 0xffff;
data16[1] = name->ord.wOrdinalID;
num = sizeof( uint_16)*2;
} else {
memcpy( mem, &(name->ord.fFlag), sizeof(uint_8)+sizeof( uint_16) );
num = sizeof(uint_8) + sizeof( uint_16) ;
}
} else {
num = WdeStringToMem( name->name, use_unicode, mem );
}
}
return( num );
}
static int WdeDialogBoxHeaderToMem( WdeDialogBoxHeader *head, uint_8 *mem )
{
Bool ok;
int pos, size;
uint_16 pointsize;
DialogBoxHeader32 h32;
DialogBoxHeader h16;
void *d;
ok = ( head && mem );
if( ok ) {
if( head->is32bit ) {
pos = offsetof( DialogBoxHeader32, MenuName );
h32.Style = head->Style;
h32.ExtendedStyle = head->ExtendedStyle;
h32.NumOfItems = head->NumOfItems;
h32.Size = head->Size;
d = &h32;
} else {
pos = offsetof( DialogBoxHeader, MenuName );
h16.Style = head->Style;
h16.NumOfItems = head->NumOfItems;
h16.Size = head->Size;
d = &h16;
}
ok = ( pos != 0 );
}
if( ok ) {
memcpy( mem, d, pos );
size = WdeNameOrOrdToMem( GETHDR_MENUNAME(head), head->is32bit, mem+pos );
ok = ( size != 0 );
}
if( ok ) {
pos += size;
size = WdeNameOrOrdToMem( GETHDR_CLASSNAME(head), head->is32bit, mem+pos );
ok = ( size != 0 );
}
if( ok ) {
pos += size;
size = WdeStringToMem( GETHDR_CAPTION(head), head->is32bit, mem+pos );
ok = ( size != 0 );
}
if( ok && ( GETHDR_STYLE(head) & DS_SETFONT ) ) {
pos += size;
pointsize = GETHDR_POINTSIZE(head);
memcpy( mem+pos, &pointsize, sizeof(uint_16) );
pos += sizeof(uint_16);
size = WdeStringToMem( GETHDR_FONTNAME(head), head->is32bit, mem+pos );
ok = ( size != 0 );
}
if( ok ) {
pos += size;
} else {
pos = 0;
}
return( pos );
}
static int WdeDialogBoxExHeaderToMem( WdeDialogBoxHeader *dhd, uint_8 *mem )
{
int pos, size;
uint_16 miscbytes[2] = { 0x0001, 0xFFFF };
/* copy the miscellaneous two WORDs 01 00 FF FF */
memcpy(mem, miscbytes, sizeof(miscbytes));
pos = sizeof(miscbytes);
memcpy( mem+pos, &dhd->HelpId, sizeof(uint_32) );
pos += sizeof(uint_32);
memcpy( mem+pos, &dhd->ExtendedStyle, sizeof(uint_32) );
pos += sizeof(uint_32);
memcpy( mem+pos, &dhd->Style, sizeof(uint_32) );
pos += sizeof(uint_32);
memcpy( mem+pos, &dhd->NumOfItems, sizeof(uint_16) );
pos += sizeof(uint_16);
memcpy( mem+pos, &dhd->Size, sizeof(DialogSizeInfo) );
pos += sizeof(DialogSizeInfo);
size = WdeNameOrOrdToMem(GETHDR_MENUNAME(dhd), dhd->is32bit, mem+pos);
pos += size;
size = WdeNameOrOrdToMem(GETHDR_CLASSNAME(dhd), dhd->is32bit, mem+pos);
pos += size;
size = WdeStringToMem(GETHDR_CAPTION(dhd), dhd->is32bit, mem+pos);
pos += size;
if (GETHDR_STYLE(dhd) & DS_SETFONT) {
memcpy( mem+pos, &dhd->PointSize, sizeof(uint_16) );
pos += sizeof(uint_16);
memcpy( mem+pos, &dhd->FontWeight, sizeof(uint_16) );
pos += sizeof(uint_16);
memcpy( mem+pos, &dhd->FontItalic, sizeof(uint_16) );
pos += sizeof(uint_16);
size = WdeStringToMem( dhd->FontName, dhd->is32bit, mem+pos );
pos += size;
}
return(pos);
}
static int WdeDialogBoxControlToMem( WdeDialogBoxControl *control,
uint_8 *mem, Bool is32bit,
Bool is32bitEx )
{
DialogBoxControl *c16;
DialogBoxControl32 *c32;
DialogBoxExControl32 *c32ex;
ControlClass *cclass;
int pos, size;
uint_16 *data16;
Bool ok;
ok = ( control && mem );
if( ok ) {
if( is32bit ) {
if( is32bitEx ) {
pos = offsetof( DialogBoxExControl32, ClassID );
c32ex = (DialogBoxExControl32 *)mem;
c32ex->HelpId = control->HelpId;
c32ex->Style = control->Style;
c32ex->ExtendedStyle = control->ExtendedStyle;
c32ex->Size = control->Size;
c32ex->ID = control->ID;
} else {
pos = offsetof( DialogBoxControl32, ClassID );
c32 = (DialogBoxControl32 *)mem;
c32->Style = control->Style;
c32->ExtendedStyle = control->ExtendedStyle;
c32->Size = control->Size;
c32->ID = control->ID;
}
} else {
pos = offsetof( DialogBoxControl, ClassID );
c16 = (DialogBoxControl *)mem;
c16->Size = control->Size;
c16->ID = control->ID;
c16->Style = control->Style;
}
cclass = GETCTL_CLASSID( control );
if( cclass->Class & 0x80 ) {
if( is32bit ) {
data16 = (uint_16 *)(mem+pos);
data16[0] = 0xffff;
data16[1] = (uint_16)cclass->Class;
size = sizeof(uint_16)*2;
} else {
memcpy( mem+pos, &(cclass->Class), sizeof(uint_8) );
size = sizeof(uint_8);
}
} else {
size = WdeStringToMem( cclass->ClassName, is32bit, mem+pos );
ok = ( size != 0 );
}
}
if( ok ) {
pos += size;
size = WdeNameOrOrdToMem( GETCTL_TEXT(control), is32bit, mem+pos );
ok = ( size != 0 );
}
if( ok ) {
pos += size;
if( is32bit ) {
memcpy( mem+pos, &control->ExtraBytes, sizeof(uint_16) );
size = sizeof(uint_16);
} else {
uint_8 eb = control->ExtraBytes;
memcpy( mem+pos, &eb, sizeof(uint_8) );
size = sizeof(uint_8);
}
}
if ( ok ) {
pos += size;
} else {
pos = 0;
}
return ( pos );
}
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 );
}
WdeDialogBoxInfo *WdeMem2DBI( uint_8 *data, uint_32 size, Bool is32bit )
{
WdeDialogBoxInfo *dbi;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -