Just copied and adjusted the example. The error is when writing the bitmap to the stream, and the bitmap is drawn correctly if I don't use transparency and streams:
procedure TForm1.Button2Click(Sender: TObject);
var
buffer: THandle;
bmp: TBitmap;
memstream: TMemoryStream;
begin
bmp := TBitmap.Create;
bmp.Width:=32;
bmp.Height:=32;
//bmp.PixelFormat:=pf24Bit ;
Handle := LoadBitmap(hInstance, 'test');
if (buffer = 0) then exit; // Error loading the bitmap
bmp.Handle := buffer;
memstream := TMemoryStream.create;
try
bmp.SaveToStream(memstream);
memstream.position := 0;
bmp.LoadFromStream(memstream);
finally
memstream.free;
end;
bmp.Transparent := True;
bmp.TransparentColor := clblack;
Canvas.Draw(100, 150, bmp);
bmp.Free; // Release allocated resource
end;