When is memory not memory ???

This is not necessarily a Delphi question, but there are a lot of
Graphics API experts here...

Can anyone explain this weirdness that I encountered trying to call
CreateIconFromResourceEx to create a 24 bits-per-pixel icon on NT4.  On
Windows 98 and Windows 2000 you don't get these problems...

I create the icon like this...
function CreateIcon (stream : TMemoryStream) : HICON;
var
 info : PBitmapInfoHeader;
begin
  info := PBitmapInfoHeader (stream.Memory);
  result := CreateIconFromResourceEx (PByte (stream.Memory),
stream.Size, True, $00030000, info^.biWidth, info^.biHeight div 2,
LR_DEFAULTCOLOR);

  if result = 0 then
    raise Exception.Create ('Unable to create icon');

  // For testing..

  DrawIconEx (GetDC (0), 0, 400, result, info^.biWidth, info^.biHeight
div 2, 0, 0, DI_NORMAL)
end;

.. but it draws gibberish (on NT4.  Other operating systems work fine,
and it works fine on NT4 with <= 256 colour icon resource streams).

But here's the weird bit.  If I copy the memory stream to a temporary
buffer, and use that instead, it works!

function CreateIcon (stream : TMemoryStream) : HICON;
var
 info : PBitmapInfoHeader;
 buffer : PChar;
begin
  GetMem (buffer, stream.Size);
  try
    Move (stream.Memory^, buffer^, stream.Size);
    info := PBitmapInfoHeader (buffer);
    result := CreateIconFromResourceEx (PByte (buffer), stream.Size,
True, $00030000, info^.biWidth, info^.biHeight div 2, LR_DEFAULTCOLOR);

    if result = 0 then
      raise Exception.Create ('Unable to create icon');

  // For testing..

    DrawIconEx (GetDC (0), 0, 400, result, info^.biWidth,
info^.biHeight div 2, 0, 0, DI_NORMAL)
  finally
    FreeMem (buffer)
  end
end;

Why on earth?  What's the difference between memory allocated with
GetMem and memory from a TMemoryStream.  I did some more digging, and
found that if you allocate the memory with GlobalAlloc it only works if
you use GMEM_MOVEABLE.  It all seems weird to me.  Are there any other
cases where you have to allocate memory with GMEM_MOVEABLE when doing
graphics ??

Colin
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm