hi

i've tryed translating cpp function to pascal , but it dosen't work
the function is simply convert jpeg file to HBITMAP Object , using IPicture interface

the cpp code work fine , could any one correct my pascal translation !!

// CPP CODE
Code:
 HBITMAP Ole2BITMAP(char *szFile)
{

HBITMAP hBitmap;
HBITMAP bmp;
DWORD dwFileSize;
DWORD dwBytesRead;
HANDLE hFile;
LPPICTURE gpPicture;
LPVOID lpPicData;
LPVOID pvData;
LPSTREAM pstm;
LPVOID hrlp;
HGLOBAL hGlobal;
BITMAP bm ;

 

hFile=CreateFile(szFile,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
dwFileSize=GetFileSize(hFile,NULL);


pvData=NULL;
hGlobal=GlobalAlloc(GMEM_MOVEABLE,dwFileSize);
pvData=GlobalLock(hGlobal);
ReadFile(hFile,pvData,dwFileSize,&dwBytesRead,NULL);
GlobalUnlock(hGlobal);
CloseHandle(hFile);


CreateStreamOnHGlobal(hGlobal,TRUE,&pstm);
OleLoadPicture(pstm,0,FALSE,IID_IPicture,(void**)&gpPicture);
pstm->Release();
gpPicture->get_Handle((OLE_HANDLE*)&hBitmap);

GetObject (hBitmap, sizeof (BITMAP), (PSTR) &bm) ;



bmp = (HBITMAP)CopyImage(hBitmap,IMAGE_BITMAP,bm.bmWidth, bm.bmHeight,LR_COPYRETURNORG);
return bmp;

}

// PASCAL TRANSLATION

Code:
uses activex
function ole2bitmap(name : string): HBITMAP;
var hBmp ,bmp : HBITMAP;
  dwFileSize,dwBytesRead : DWORD;
  hFile : integer;
  gpPicture : IPicture;
  pvData  : pointer;
  pstm   : ISTREAM;
  hGlob   : hGlobal;
  bm    : BITMAP;
begin

  hFile := CreateFile(Pchar(name),GENERIC_READ,0,NIL,OPEN_EXISTING,0,0);
  dwFileSize :=GetFileSize(hFile,NIL);

  pvData := NIL;
  hGlob := GlobalAlloc(GMEM_MOVEABLE,dwFileSize);
  pvData:=GlobalLock(hGlob);
  ReadFile(hFile,pvData,dwFileSize,dwBytesRead,NIL);
  GlobalUnlock(hGlob);
  CloseHandle(hFile);

  CreateStreamOnHGlobal(hGlob,TRUE,pstm);
  OleLoadPicture(pstm,0,FALSE,IPICTURE,gpPicture);
  pstm._Release();
  gpPicture.get_Handle(LongWord(hBmp));

  GetObject (hBmp, sizeof (BITMAP), @bm) ;

  bmp := CopyImage(hBmp,IMAGE_BITMAP,bm.bmWidth, bm.bmHeight,LR_COPYRETURNORG);

 Result := bmp;

end;
thanks