Page 1 of 1

[madRes] SaveIconGroupResourceW

Posted: Sat Dec 29, 2007 8:28 am
by MarcT
Hi,

I want to be able to save the MainIcon group of a file to a .ico, so to start, I'm assuming the name of the main icon group is MAINICON, but I'm having a problem, it seems I need to know the resource language, for example, this doesn't work:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  resUpdateHandle : dword;
begin

  resUpdateHandle := BeginUpdateResourceW(PWideChar(wideString('calc.exe')), false);
  if resUpdateHandle <> 0 then
  begin

    SaveIconGroupResourceW(resUpdateHandle, 'SC', 0, 'test.ico');
    EndUpdateResourceW(resUpdateHandle, true);
  end;

end;
but this works:

Code: Select all

function MAKELANGID(sPrimaryLanguage : Word;
                    sSubLanguage : Word) : Word;
begin
  result := (sSubLanguage shl 10) or
             sPrimaryLanguage;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  resUpdateHandle : dword;
begin

  resUpdateHandle := BeginUpdateResourceW(PWideChar(wideString('calc.exe')), false);
  if resUpdateHandle <> 0 then
  begin

    SaveIconGroupResourceW(resUpdateHandle, 'SC', makelangid(LANG_FRENCH,SUBLANG_DEFAULT), 'test.ico');
    EndUpdateResourceW(resUpdateHandle, true);
  end;

end;

lol it works because I know my calc.exe is in french but I wouldn't normally know this for a file,

so how can I fix this?:/

thx

Posted: Sat Dec 29, 2007 8:53 am
by ciuly
I suppose you are marc582 from EE :P

you need to enumerate the icons and store their info before making generic changes. see this thread: viewtopic.php?t=273

Posted: Sat Dec 29, 2007 8:58 am
by MarcT
lol yes, I am,

ok so, from what I've seen, the guy on the thread seems to ignore the language:
I can save the main icon like this:
result := SaveIconGroupResourceW(resUpdateHandle, 'MAINICON', 0, 'c:\test.ico');

But how do I save an icon called "74" from RT_ICONS?
result := SaveIconGroupResourceW(resUpdateHandle, 'RT_ICON_74', 0, 'c:\test2.ico'); // does not work
he use 0,

why?

I thought the enumerating thing was just to know the icon group, we also use this to know the language of icon?

damn I'm becoming bored, I'm trying to do this since so many days... :S


Marc and thx.

Posted: Sat Dec 29, 2007 9:09 am
by ciuly
well he only needed names :)
you will have to call EnumResourceLanguages instead of EnumResourceNames to save the languages as well ;) (EnumResourceLanguages also passes you the names so no problem there)

Posted: Sat Dec 29, 2007 9:35 am
by MarcT
mmm ok thx but mmm

give me more hint plz, i hate those fucking api, i never know what to fill as parameter, msdn is never clear :@

Posted: Sat Dec 29, 2007 10:32 am
by ciuly
for future reference, discussion will be continued here: http://www.experts-exchange.com/Program ... 46543.html