an_icon *IconResourceToIcon( FILE *fp, an_icon_file *icon_file, unsigned i ) { an_icon_resource *res; BITMAPINFO *bm; BITMAPINFOHEADER *h; an_icon *icon; if( i >= icon_file->count ) return( NULL ); res = &icon_file->resources[ i ]; fseek( fp, res->DIB_offset, SEEK_SET ); bm = ReadIconBitmap( fp ); if( bm ) { icon = UtilMalloc( sizeof( an_icon ) ); icon->bm = bm; h = &bm->bmiHeader; // h->biHeight /= 2; /* code gen bug */ h->biHeight = res->height; /* they have height * 2 in this field */ h->biSizeImage = BITS_TO_BYTES( h->biWidth * h->biBitCount, h->biHeight ); icon->xor_size = h->biSizeImage; icon->and_size = BITS_TO_BYTES( h->biWidth, h->biHeight ); icon->xor_mask = UtilMalloc( icon->xor_size + icon->and_size ); icon->and_mask = (char *)icon->xor_mask + icon->xor_size; fseek( fp, res->DIB_offset + BITMAP_SIZE( h ), SEEK_SET ); fread( icon->xor_mask, icon->xor_size + icon->and_size, 1, fp ); return( icon ); } return( NULL ); } /* IconResourceToIcon */
static HPALETTE CreateIconPalette( BITMAPINFO *info ) { unsigned num_colours, i; LOGPALETTE *palette; HPALETTE palette_handle; RGBQUAD *quads; num_colours = info->bmiHeader.biClrUsed; if( num_colours == 0 ) { num_colours = 1 << info->bmiHeader.biBitCount; } palette = UtilMalloc( sizeof( LOGPALETTE ) + num_colours * sizeof( PALETTEENTRY ) ); palette->palNumEntries = num_colours; palette->palVersion = 0x300; quads = &info->bmiColors[0]; for( i = 0; i < num_colours; i++ ) { palette->palPalEntry[i].peRed = quads[i].rgbRed; palette->palPalEntry[i].peGreen = quads[i].rgbGreen; palette->palPalEntry[i].peBlue = quads[i].rgbBlue; palette->palPalEntry[i].peFlags = 0; } palette_handle = CreatePalette( palette ); UtilFree( palette ); return( palette_handle ); } /* CreateIconPalette */
CRWLock::CRWLock() : m_pRWLock(0) { m_pRWLock = UtilMalloc(sizeof(pthread_rwlock_t)); if (pthread_rwlock_init((pthread_rwlock_t*)m_pRWLock,0) != UTIL_OK) { UtilFree(m_pRWLock); m_pRWLock = 0; } }
/* * This is the window proc for an individual MDI child window containing * a displayable icon. */ LONG _EXPORT FAR PASCAL MdiIconProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { an_MDI_icon *icon; HDC hdc; PAINTSTRUCT ps; RECT rect; icon = (an_MDI_icon *) GetWindowLong( hwnd, 0 ); switch( msg ) { case WM_CREATE: icon = UtilMalloc( sizeof( an_MDI_icon ) ); icon->XOR_bitmap = 0; /* use as flag so we don't paint */ SetWindowLong( hwnd, 0, (LONG) (LPVOID) icon ); break; case WM_COMMAND: if( LOWORD( wparam ) == IDM_SWITCHICON ) { if( SwitchIcon( icon ) ) { ReloadIcon( hwnd, icon ); InvalidateRect( hwnd, NULL, TRUE ); UpdateWindow( hwnd ); } } break; case WM_PAINT: if( icon->XOR_bitmap ) { hdc = BeginPaint( hwnd, &ps ); /* draw the bitmap in the client area of the MDI window */ GetClientRect( hwnd, &rect ); DrawMdiIcon( hdc, icon, &rect ); EndPaint( hwnd, &ps ); } break; case WM_DESTROY: /* destroy the BITMAP and the ICON */ DeleteObject( icon->XOR_bitmap ); DeleteObject( icon->AND_bitmap ); UtilFree( icon->file_name ); UtilFree( icon ); break; default: return( DefMDIChildProc( hwnd, msg, wparam, lparam ) ); } return( 0 ); } /* MdiIconProc */
static BITMAPINFO *ReadIconBitmap( FILE *fp ) { BITMAPINFO *bm; BITMAPINFOHEADER *header; long DIB_offset, bitmap_size; header = UtilMalloc( sizeof( BITMAPINFOHEADER ) ); DIB_offset = ftell( fp ); fread( header, sizeof( BITMAPINFOHEADER ), 1, fp ); fseek( fp, DIB_offset, SEEK_SET ); bitmap_size = BITMAP_SIZE( header ); bm = realloc( header, bitmap_size ); if( !bm ) return( NULL ); fread( bm, bitmap_size, 1, fp ); return( bm ); } /* ReadIconBitmap */
Bool CXmlFile::ParseFile(const AString& sFile, PVoid pDoc) { CDiskFile xFile; if (!pDoc || !xFile.Open(sFile)) return false; Size_t iSize = (Size_t)(xFile.GetFileSize() + 8); Char* pData = (Char*)UtilMalloc(iSize); CScope::CMallocPtr scope(pData); memset(pData, 0, iSize); iSize = (Size_t)xFile.Read(pData, xFile.GetFileSize()); xFile.Close(); //解析文档 return ParseDocument(pDoc, pData); }
void* UtilRealloc(void* pMem, Size_t iSize) { if (!pMem) return UtilMalloc(iSize); if (!iSize) { UtilFree(pMem); return 0; } #if NED_MALLOC return nedalloc::nedrealloc(pMem, iSize); #else return realloc(pMem, iSize); #endif }
an_icon_file *IconOpen( FILE *fp ) { an_icon_file *icon_file; unsigned size; icon_file = UtilMalloc( sizeof( an_icon_file ) ); /* read the header once to find out how many icons are in the file */ fseek( fp, 0L, SEEK_SET ); fread( icon_file, sizeof( an_icon_file ), 1, fp ); if( icon_file->count > 1 ) { size = sizeof( an_icon_file ) + sizeof( an_icon_resource ) * ( icon_file->count - 1 ); icon_file = realloc( icon_file, size ); fseek( fp, 0L, SEEK_SET ); fread( icon_file, (long) size, 1, fp ); } return( icon_file ); } /* IconOpen */
CMutex::CMutex(Bool bRecursive) : m_pMutex(0) { pthread_mutexattr_t sAttr; pthread_mutexattr_init(&sAttr); pthread_mutexattr_settype(&sAttr, bRecursive? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); m_pMutex = UtilMalloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init((pthread_mutex_t*)m_pMutex, &sAttr) != UTIL_OK) { UtilFree(m_pMutex); m_pMutex = 0; } pthread_mutexattr_destroy(&sAttr); #ifdef _DEBUG m_bLocked = false; m_sFile = ""; m_iLine = 0; m_iThread = 0; #endif }