views:

54

answers:

1

Hello all!

I've run into the following problem:

My Delphi7 program runs smoothly on most computers running WinXP/Vista/7 BUT on some older Windows XP installs (only a few) I'm getting the following problem:

I have a system image list, and I'm adding my own icons to a copy of the system image list. Upon adding my icons I get an "Invalid image size." EInvalidOperation error.

Here is the code in question:

function GetSystemLargeIconsList: TCustomImageList;
// This gets the system image list.
var
  SysIL: HImageList;
  SFI: TSHFileInfo;
  MyImages: TCustomImageList;
begin
  SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
     SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
  if SysIL <> 0 then begin
    MyImages:=TCustomImageList.Create(nil);
    // Assign the system list to the component
    MyImages.Handle := SysIL;
 // The following prevents the image list handle from being
 // destroyed when the component is.
    MyImages.ShareImages := TRUE;
    Result:=MyImages;
  end;
end;

var
    DocumentImgList: TCustomImageList;
    IconToAdd: TIcon;
begin
    DocumentImgList:=GetSystemLargeIconsList;

    Documents.LargeImages:=DocumentImgList;
    Documents.SmallImages:=DocumentImgList;

    IconToAdd:=TIcon.Create;

    DocumentListIcons.GetIcon(0, IconToAdd);
    DocumentImgList.AddIcon(IconToAdd); ----> this is the line of the exception

To make the problem worse, I'm using the TPngImageList component, but according to the code, it just seems to call the standard Delphi function:

if TObject(Self) is TPngImageList
then if Image = nil

...

else begin
     Patch := FindMethodPatch('AddIcon');
     if Patch <> nil
     then begin
          Patch.BeginInvokeOldMethod;
          try
            Result := TCustomImageList(Self).AddIcon(Image); ----> this is where the exception happens
          finally
            Patch.FinishInvokeOldMethod;
           end;
          end
     else Result := -1;
     end;

I've recently found out that on one of the computers that have this problem, either uxtheme.dll or explorer.exe has been patched with some Windows-skinning program.

So I suppose that somebody or a program is hacking the system image list in a way that is making my Delphi program crash.

Any ideas on how to fix this?

Thanks!

+1  A: 

One thing you could try would be to load your icon into a separate tBitmap, then resize it before adding it into the image list.

skamradt
Problem is that I can't properly test it... My code relies heavily on the above (becuase it works on XP/Vista and 7) and even if I rewrite it there is no guarantee that it would work... I'm pretty sure that it's a Delphi7 issue! That's why I'm asking if anyone has seen something similar before...
Steve
If you can't test it, then how do you know what line the error is occurring at? Wrapping the GetIcon into a separate function doesn't seem like a risky solution, since you should be able to verify the correct behavior with a machine that doesn't experience the problem. Then test it on one that does.
skamradt
I'm using EurekaLog to trace bugs - it is giving me back the line number. Can you give some example code for your solution? Will this properly work with icons which have a transparent background?
Steve