Beispiel #1
0
WResResNode *WRReadWResResNodeFromExe( WResFileID file, uint_16 align )
{
    WRNameInfo      name_info;
    uint_32         offset_32;
    uint_32         length_32;
    WResResNode     *rnode;
    WResLangNode    *lnode;

    rnode = (WResResNode *)WRMemAlloc( sizeof( WResResNode ) );
    if( rnode == NULL ) {
        return( NULL );
    }

    lnode = (WResLangNode *)WRMemAlloc( sizeof( WResLangNode ) );
    if( lnode == NULL ) {
        WRMemFree( rnode );
        return( NULL );
    }

    if( read( file, &name_info, sizeof( WRNameInfo ) ) != sizeof( WRNameInfo ) ) {
        return( NULL );
    }

    rnode->Next = NULL;
    rnode->Prev = NULL;
    rnode->Head = lnode;
    rnode->Tail = lnode;
    rnode->Info.NumResources = 1;
    if( name_info.id & 0x8000 ) {
        rnode->Info.ResName.IsName = FALSE;
    } else {
        rnode->Info.ResName.IsName = TRUE;
    }
    rnode->Info.ResName.ID.Num = (name_info.id & 0x7fff);

    lnode->Next = NULL;
    lnode->Prev = NULL;
    lnode->data = NULL;
    lnode->Info.MemoryFlags = name_info.flags;
    offset_32 = (uint_32)name_info.offset;
    length_32 = (uint_32)name_info.length;
    lnode->Info.Offset = (uint_32)(offset_32 << align);
    lnode->Info.Length = (uint_32)(length_32 << align);
    lnode->Info.lang.lang = DEF_LANG;
    lnode->Info.lang.sublang = DEF_SUBLANG;

    return( rnode );
}
Beispiel #2
0
char *WdeGetStrFromListBox( HWND hDlg, int id, int index )
{
    char    *cp;
    int     text_length;
    int     text_copied;
    int     count;

    count = (int)SendDlgItemMessage( hDlg, id, LB_GETCOUNT, 0, 0 );
    if( count == 0 || count == LB_ERR || count < index ) {
        return( NULL );
    }

    text_copied = 0;

    text_length = SendDlgItemMessage( hDlg, id, LB_GETTEXTLEN, index, 0 );

    cp = (char *)WRMemAlloc( text_length + 1 );
    if( cp == NULL ) {
        return( NULL );
    }

    text_copied = SendDlgItemMessage( hDlg, id, LB_GETTEXT, index, (LPARAM)(LPSTR)cp );

    if( text_copied != text_length ) {
        WRMemFree( cp );
        return( NULL );
    }

    cp[text_length] = '\0';

    return( cp );
}
Beispiel #3
0
void WHandleMemFlags( WStringEditInfo *einfo )
{
    char        *rtext;
    char        *ntext;
    WResID      *rname;

    ntext = AllocRCString( W_STRINGNAMES );
    if( einfo != NULL && einfo->current_block != NULL && ntext != NULL ) {
        WSetStatusByID( einfo->wsb, W_CHANGESTRINGMEMFLAGS, -1 );
        // alloc space for ntext and two 16-bit ints
        rtext = (char *)WRMemAlloc( strlen( ntext ) + 20 );
        if( rtext != NULL ) {
            sprintf( rtext, ntext, einfo->current_block->blocknum & 0xfff0,
                     (einfo->current_block->blocknum & 0xfff0) + 16 - 1 );
        }
        rname = WResIDFromStr( rtext );
        if( rname != NULL ) {
            einfo->info->modified |= WChangeMemFlags( einfo->win,
                                                      &einfo->current_block->MemFlags,
                                                      rname, WGetEditInstance(),
                                                      WStrHelpRoutine );
            WRMemFree( rname );
        }
        FreeRCString( ntext );
        WSetStatusReadyText( einfo->wsb );
    }
}
Beispiel #4
0
void *WdeHData2Mem( HDDEDATA hData )
{
    void        *mem;
    uint_32     size;

    if( hData == (HDDEDATA)NULL ) {
        return( NULL );
    }

    size = (uint_32)DdeGetData( hData, NULL, 0, 0 );
    if( size == 0 ) {
        return( NULL );
    }

    mem = WRMemAlloc( size );
    if( mem == NULL ) {
        return( NULL );
    }

    if( (DWORD)size != DdeGetData( hData, mem, (DWORD)size, 0 ) ) {
        WRMemFree( mem );
        return( NULL );
    }

    return( mem );
}
Beispiel #5
0
static bool WdeAddStyleString( char **text, char *str )
{
    int slen;
    int tlen;

    if( text == NULL || str == NULL ) {
        return( FALSE );
    }

    slen = strlen( str );

    if( *text == NULL ) {
        *text = WRMemAlloc( slen + 1 );
        if( *text != NULL ) {
            strcpy( *text, str );
        }
    } else {
        tlen = strlen( *text );
        tlen += slen + 3 + 1;
        *text = (char *)WRMemRealloc( *text, tlen );
        if( *text != NULL ) {
            strcat( *text, " | " );
            strcat( *text, str );
        }
    }

    return( *text != NULL );
}
Beispiel #6
0
int WRReadResourceNames( WResDir dir, WResFileID file_handle, uint_32 name_offset )
{
    uint_8      name_len;
    char        *name;
    int         end_of_names;

    end_of_names = FALSE;

    ResReadUint8( &name_len, file_handle );

    while( !end_of_names ) {
        if( name_len == 0 ) {
            ResReadUint8( &name_len, file_handle );
            if( name_len == 0 ) {
                end_of_names = TRUE;
            } else {
                name_offset++;
            }
        } else {
            name = (char *)WRMemAlloc( name_len + 1 );
            if( read( file_handle, name, name_len ) != name_len ) {
                return( FALSE );
            }
            name[name_len] = 0;
            WRSetResName( dir, name_offset, name );
            WRMemFree( name );
            name_offset = name_offset + name_len + 1;
            ResReadUint8( &name_len, file_handle );
        }
    }

    return( TRUE );
}
Beispiel #7
0
WResResNode *WRRenameWResResNode( WResTypeNode *type_node,
                                  WResResNode *res_node, char *name )
{
    WResResNode *new_res_node;
    int         len;

    len = strlen( name );
    new_res_node = (WResResNode *)WRMemAlloc( sizeof( WResResNode ) + max( 0, len - 1 ) );
    if( new_res_node == NULL ) {
        return( NULL );
    }
    if( type_node->Head == res_node ) {
        type_node->Head = new_res_node;
    }
    if( type_node->Tail == res_node ) {
        type_node->Tail = new_res_node;
    }
    new_res_node->Head = res_node->Head;
    new_res_node->Tail = res_node->Tail;
    new_res_node->Next = res_node->Next;
    new_res_node->Prev = res_node->Prev;
    new_res_node->Info.ResName.IsName = TRUE;
    new_res_node->Info.ResName.ID.Name.NumChars = len;
    memcpy( new_res_node->Info.ResName.ID.Name.Name, name, len );
    if( res_node->Prev != NULL ) {
        res_node->Prev->Next = new_res_node;
    }
    if( res_node->Next != NULL ) {
        res_node->Next->Prev = new_res_node;
    }
    WRMemFree( res_node );
    return( new_res_node );
}
Beispiel #8
0
WResTypeNode *WRRenameWResTypeNode( WResDir dir, WResTypeNode *type_node, char *name )
{
    WResTypeNode    *new_type_node;
    int             len;

    len = strlen( name );
    new_type_node = (WResTypeNode *)WRMemAlloc( sizeof( WResTypeNode ) + len - 1 );
    if( new_type_node == NULL ) {
        return( NULL );
    }
    if( dir->Head == type_node ) {
        dir->Head = new_type_node;
    }
    if( dir->Tail == type_node ) {
        dir->Tail = new_type_node;
    }
    new_type_node->Next = type_node->Next;
    new_type_node->Prev = type_node->Prev;
    new_type_node->Head = type_node->Head;
    new_type_node->Tail = type_node->Tail;
    new_type_node->Info.NumResources = type_node->Info.NumResources;
    new_type_node->Info.TypeName.IsName = TRUE;
    new_type_node->Info.TypeName.ID.Name.NumChars = len;
    memcpy( new_type_node->Info.TypeName.ID.Name.Name, name, len );
    if( type_node->Prev != NULL ) {
        type_node->Prev->Next = new_type_node;
    }
    if( type_node->Next != NULL ) {
        type_node->Next->Prev = new_type_node;
    }
    WRMemFree( type_node );
    return( new_type_node );
}
Beispiel #9
0
uint_32 WRUseNameTable( WResDir dir, uint_8 *name_table, uint_32 len, uint_8 **leftover )
{
    WRNameTableEntry    *entry;
    uint_32             name_pos;
    uint_32             num_leftover;

    name_pos = 0;
    num_leftover = 0;
    while( name_pos < len ) {
        entry = (WRNameTableEntry *)(name_table + name_pos);
        if( entry->length == 0 ) {
            break;
        }
        if( name_pos + entry->length > len ) {
            num_leftover = len - name_pos;
            *leftover = (uint_8 *)WRMemAlloc( num_leftover );
            if( *leftover != NULL ) {
                memcpy( *leftover, entry, num_leftover );
            } else {
                /* leftover alloc failed! */
            }
            break;
        }
        WRSetResNameFromNameTable( dir, entry );
        name_pos += entry->length;
    }

    return( num_leftover );
}
Beispiel #10
0
static bool WSetFlagsText( uint_16 flags, char **text )
{
    int         tlen;

    if( text == NULL ) {
        return( FALSE );
    }

    tlen = 0;
    *text = NULL;

    if( flags & ACCEL_VIRTKEY ) {
        tlen += sizeof( VirtualText ) + 2;
    }

    if( flags & ACCEL_SHIFT ) {
        tlen += sizeof( ShiftText ) + 2;
    }

    if( flags & ACCEL_ALT ) {
        tlen += sizeof( AltText ) + 2;
    }

    if( flags & ACCEL_CONTROL ) {
        tlen += sizeof( ControlText ) + 2;
    }

    if( tlen == 0 ) {
        return( TRUE );
    }

    *text = (char *)WRMemAlloc( tlen + 1 );
    if( *text == NULL ) {
        return( FALSE );
    }

    (*text)[0] = '\0';

    if( flags & ACCEL_VIRTKEY ) {
        strcat( *text, ", " );
        strcat( *text, VirtualText );
    }

    if( flags & ACCEL_SHIFT ) {
        strcat( *text, ", " );
        strcat( *text, ShiftText );
    }

    if( flags & ACCEL_ALT ) {
        strcat( *text, ", " );
        strcat( *text, AltText );
    }

    if( flags & ACCEL_CONTROL ) {
        strcat( *text, ", " );
        strcat( *text, ControlText );
    }

    return( TRUE );
}
Beispiel #11
0
char *WGetStrFromEdit( HWND edit, bool *mod )
{
    char    *cp;
    LRESULT text_length;
    LRESULT text_copied;

    text_copied = 0;

    if( mod != NULL ) {
        /* find out if the edit field has changed */
        if( SendMessage( edit, EM_GETMODIFY, 0, 0 ) ) {
            *mod = TRUE;
        } else {
            *mod = FALSE;
        }
    }

    text_length = SendMessage( edit, WM_GETTEXTLENGTH, 0, 0 );

    cp = (char *)WRMemAlloc( text_length + 1 );
    if( cp == NULL ) {
        return( NULL );
    }

    text_copied = SendMessage ( edit, WM_GETTEXT, text_length + 1, (LPARAM)(LPSTR)cp );

    if( text_copied > text_length ) {
        WRMemFree( cp );
        return( NULL );
    }

    cp[text_length] = '\0';

    return( cp );
}
Beispiel #12
0
WResResNode *WdeAllocWResResNode( uint_16 num_resources, WResID *name )
{
    WResResNode *new_rnode;
    size_t      len;

    if( name == NULL ) {
        return( NULL );
    }

    len = sizeof( WResResNode );
    if( name->IsName ) {
        if( name->ID.Name.NumChars != 0 ) {
            len += name->ID.Name.NumChars - 1;
        }
    }
    new_rnode = (WResResNode *)WRMemAlloc( len );
    if( new_rnode != NULL ) {
        new_rnode->Head = NULL;
        new_rnode->Tail = NULL;
        new_rnode->Next = NULL;
        new_rnode->Prev = NULL;
        new_rnode->Info.NumResources = num_resources;
        len -= sizeof( WResResNode ) - sizeof( WResID );
        memcpy( &new_rnode->Info.ResName, name, len );
    }

    return( new_rnode );
}
Beispiel #13
0
bool WREHData2Mem( HDDEDATA hData, void **data, uint_32 *size )
{
    DWORD   dde_size;

    if( data == NULL || size == NULL || hData == (HDDEDATA)NULL ) {
        return( FALSE );
    }

    *size = dde_size = DdeGetData( hData, NULL, 0, 0 );
    if( dde_size == 0 ) {
        return( FALSE );
    }

    *data = WRMemAlloc( dde_size );
    if( *data == NULL ) {
        return( FALSE );
    }

    if( dde_size != DdeGetData( hData, *data, dde_size, 0 ) ) {
        WRMemFree( *data );
        return( FALSE );
    }

    return( TRUE );
}
Beispiel #14
0
void *RcMemMalloc( unsigned size )
{
#ifdef DEBUG_RCMEM
    return ( WRMemAlloc( size ) );
#else
    return ( malloc( size ) );
#endif
}
Beispiel #15
0
void WInitDummyMenuEntry( void )
{
    WDummyMenuEntry = (WMenuEntry *)WRMemAlloc( sizeof( WMenuEntry ) );
    memset( WDummyMenuEntry, 0, sizeof( WMenuEntry ) );
    WDummyMenuEntry->item = ResNewMenuItem();
    WDummyMenuEntry->item->Item.Normal.ItemText = AllocRCString( W_MENUITEM );
    WDummyMenuEntry->item->Item.Normal.ItemID = 101;
}
Beispiel #16
0
bool WREGetAndAddIconImage( BYTE *data, WResDir dir, ICONDIRENTRY *id, int ord )
{
    BYTE                *icon;
    int                 dup;
    WResID              *tname;
    WResID              *rname;
    WResLangType        lang;
    bool                ok;

    dup = FALSE;
    lang.lang = DEF_LANG;
    lang.sublang = DEF_SUBLANG;
    tname = NULL;
    rname = NULL;

    ok = (data != NULL && dir != NULL && id != NULL && id->dwBytesInRes != 0);

    if( ok ) {
        icon = (BYTE *)WRMemAlloc( id->dwBytesInRes );
        ok = (icon != NULL);
    }

    if( ok ) {
        memcpy( icon, data + id->dwImageOffset, id->dwBytesInRes );
        tname = WResIDFromNum( (uint_16)RT_ICON );
        ok = (tname != NULL);
    }

    if( ok ) {
        rname = WResIDFromNum( ord );
        ok = (rname != NULL);
    }

    if ( ok ) {
        ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0,
                               id->dwBytesInRes, dir, &lang, &dup );
    }

    if( ok ) {
        ok = WRFindAndSetData( dir, tname, rname, &lang, icon );
    }

    if( !ok ) {
        if( icon != NULL ) {
            WRMemFree( icon );
        }
    }

    if( tname != NULL ) {
        WRMemFree( tname );
    }

    if( rname != NULL ) {
        WRMemFree( rname );
    }

    return( ok );
}
Beispiel #17
0
WHndlInfo *WAllocHndlInfo( void )
{
    WHndlInfo *info;

    info = (WHndlInfo *)WRMemAlloc( sizeof( WHndlInfo ) );

    memset( info, 0, sizeof( WHndlInfo ) );

    return( info );
}
Beispiel #18
0
WRInfo * WR_EXPORT WRAllocWRInfo( void )
{
    WRInfo  *info;

    if( (info = (WRInfo *)WRMemAlloc( sizeof( WRInfo ) )) != NULL ) {
        memset( info, 0, sizeof( WRInfo ) );
    }

    return( info );
}
Beispiel #19
0
void *PP_Malloc( size_t size )
{
    void        *p;

    p = WRMemAlloc( size );
    if( p == NULL ) {
        PP_OutOfMemory();
    }
    return( p );
}
Beispiel #20
0
WMenuInfo *WRESEAPI WMenuAllocMenuInfo( void )
{
    WMenuInfo *info;

    info = (WMenuInfo *)WRMemAlloc( sizeof( WMenuInfo ) );

    memset( info, 0, sizeof( WMenuInfo ) );

    return( info );
}
Beispiel #21
0
bool WREGetClipData( WREClipFormat *fmt, void **data, uint_32 *dsize )
{
    bool        ok;
    HANDLE      hclipdata;
    void        *mem;

    hclipdata = (HANDLE)NULL;
    mem = NULL;
    ok = (fmt != NULL && fmt->fmt != 0 && data != NULL && dsize != 0);

    if( ok ) {
        hclipdata = GetClipboardData( fmt->fmt );
        ok = (hclipdata != NULL);
    }

    if( ok ) {
        mem = GlobalLock( hclipdata );
        ok = (mem != NULL);
    }

    if( ok ) {
        *dsize = (uint_32)GlobalSize( hclipdata );
        ok = (*dsize != 0);
    }

    if( ok ) {
        if( *dsize >= INT_MAX ) {
            WREDisplayErrorMsg( WRE_RESTOOLARGETOPASTE );
            ok = false;
        }
    }

    if( ok ) {
        *data = WRMemAlloc( *dsize );
        ok = (*data != NULL);
    }

    if( ok ) {
        memcpy( *data, mem, *dsize );
    }

    if( !ok ) {
        if( *data ) {
            WRMemFree( *data );
            *data = NULL;
            *dsize = 0;
        }
    }

    if( mem != NULL ) {
        GlobalUnlock( hclipdata );
    }

    return( ok );
}
Beispiel #22
0
bool WdeSetMemFlagsText( uint_16 flags, char **text )
{
    int         tlen;

    if( text == NULL ) {
        return( FALSE );
    }

    tlen = 0;
    *text = NULL;

    if( flags & MEMFLAG_PRELOAD ) {
        tlen += 8; // size of the string PRELOAD and a space
    }

    if( !(flags & MEMFLAG_MOVEABLE) ) {
        tlen += 6; // size of the string FIXED and a space
    }

    if( flags & MEMFLAG_DISCARDABLE ) {
        tlen += 12; // size of the string DISCARDABLE and a space
    }

    if( !(flags & MEMFLAG_PURE) ) {
        tlen += 7; // size of the string IMPURE and a space
    }

    if( tlen == 0 ) {
        return( TRUE );
    }

    *text = (char *)WRMemAlloc( tlen + 1 );
    if( *text == NULL ) {
        return( FALSE );
    }
    (*text)[0] = '\0';

    if( flags & MEMFLAG_PRELOAD ) {
        strcat( *text, "PRELOAD " );
    }

    if( !(flags & MEMFLAG_MOVEABLE) ) {
        strcat( *text, "FIXED " );
    }

    if( flags & MEMFLAG_DISCARDABLE ) {
        strcat( *text, "DISCARDABLE " );
    }

    if( !(flags & MEMFLAG_PURE) ) {
        strcat( *text, "IMPURE " );
    }

    return( TRUE );
}
Beispiel #23
0
WdeToolBar *WdeAllocToolBar( void )
{
    WdeToolBar *tbar;

    tbar = (WdeToolBar *)WRMemAlloc( sizeof( WdeToolBar ) );
    if( tbar != NULL ) {
        memset( tbar, 0, sizeof( WdeToolBar ) );
    }

    return( tbar );
}
Beispiel #24
0
WdeToolBarInfo *WdeAllocToolBarInfo( int num )
{
    WdeToolBarInfo *info;

    info = (WdeToolBarInfo *)WRMemAlloc( sizeof( WdeToolBarInfo ) );

    if( info != NULL ) {
        memset( info, 0, sizeof( WdeToolBarInfo ) );
        info->items = (TOOLITEMINFO *)WRMemAlloc( sizeof( TOOLITEMINFO ) * num );
        if( info->items != NULL ) {
            memset( info->items, 0, sizeof( TOOLITEMINFO ) * num );
            info->num_items = num;
        } else {
            WRMemFree( info );
            info = NULL;
        }
    }

    return( info );
}
Beispiel #25
0
WREResInfo *WREAllocResInfo( void )
{
    WREResInfo  *info;

    info = (WREResInfo *)WRMemAlloc( sizeof( WREResInfo ) );

    if( info != NULL ) {
        memset( info, 0, sizeof( WREResInfo ) );
    }

    return( info );
}
Beispiel #26
0
WREAccelSession *WREAllocAccelSession( void )
{
    WREAccelSession *session;

    session = (WREAccelSession *)WRMemAlloc( sizeof( WREAccelSession ) );

    if( session != NULL ) {
        memset( session, 0, sizeof( WREAccelSession ) );
    }

    return( session );
}
Beispiel #27
0
void *MemAlloc( unsigned size )
{
    void *p;

    p = WRMemAlloc( size );

    if( p ) {
        memset( p, 0, size );
    }

    return( p );
}
Beispiel #28
0
void *MemAlloc( size_t size )
{
    void *p;

    p = WRMemAlloc( size );

    if( p != NULL ) {
        memset( p, 0, size );
    }

    return( p );
}
Beispiel #29
0
WAccelEditInfo *WAllocAccelEInfo( void )
{
    WAccelEditInfo *einfo;

    einfo = (WAccelEditInfo *)WRMemAlloc( sizeof( WAccelEditInfo ) );

    if( einfo != NULL ) {
        memset( einfo, 0, sizeof( WAccelEditInfo ) );
        einfo->current_pos = LB_ERR;
    }

    return( einfo );
}
Beispiel #30
0
WMenuEditInfo *WAllocMenuEInfo( void )
{
    WMenuEditInfo *einfo;

    einfo = (WMenuEditInfo *)WRMemAlloc( sizeof( WMenuEditInfo ) );

    if( einfo != NULL ) {
        memset( einfo, 0, sizeof( WMenuEditInfo ) );
        einfo->current_pos = -1;
    }

    return( einfo );
}