sory że w pascalu ale nie maiłem tego kodu w c
procedure TImage.LoadFromFile(FileName: String);
var
DIB: TDIBSection;
p: IPicture;
hFile, hMem: DWORD;
dwFileSize,dwBytesRead: DWORD;
pData: pointer;
bRead: boolean;
hRes: HRESULT;
pStream: IStream;
// r: Boolean;
begin
p:= nil;
hFile:= CreateFile(PChar(FileName), GENERIC_READ, 0 ,nil, OPEN_EXISTING, 0, 0);
if hFile = INVALID_HANDLE_VALUE then Exit;
try
dwFileSize:= GetFileSize(hFile, nil);
if dwFileSize >= INVALID_FILE_SIZE then begin CloseHandle(hFile); Exit; end;
hMem:= GlobalAlloc(GMEM_MOVEABLE or GMEM_NODISCARD, dwFileSize);
if hMem <= 0 then Exit;
try
pData:= GlobalLock(hMem);
if pData <> nil then begin
bRead:= ReadFile(hFile, pData^, dwFileSize, dwBytesRead, nil);
if bRead then begin
pStream:= nil;
hRes:= CreateStreamOnHGlobal(hMem, True, pStream);
if not FAILED(hRes)and(pStream <> nil) then begin
{hRes:= }OleLoadPicture(pStream, dwFileSize, false, IID_IPicture, p);
//r:= (hRes = S_OK)and(p <> nil);
end;
end;
end;
finally
GlobalUnlock(hMem);
end;
finally
CloseHandle(hFile);
end;
pStream.Release;
pStream:= nil;
if p <> nil then begin
p.get_Handle(FBitmap);
GetObject(FBitmap, SizeOf(DIB), @DIB);
FIWidth:= dib.dsBm.bmWidth;
FIHeight:= dib.dsBm.bmHeight;
Width:= FIWidth;
Height:= FIHeight;
end;
FBitmap:= CopyImage(FBitmap, IMAGE_BITMAP, FIWidth, FIHeight, LR_COPYRETURNORG);
p.Release;
end;