| 
| 
 | Вопрос # 2 889/ вопрос открыт / | 
 |  Здравствуйте, эксперты!
 Я пишу программу на Delphi7 с kol, для замены ресурсов в файле exe dll из другого файла dll. Но я столкнулся с проблемой, когда пытаюсь заменить иконку из одного dll файла в другой. Замена идет не правильно. Как исправить? Еще хотелось бы знать как засунуть любую иконку в файл Dll правильно, т.е. имеется файл new.ico и мне надо записать его как-то в ресурс файла RT_GROUP_ICON и RT_ICON, так чтобы было правильно все и на другие иконки не повлияло. Как такое сделать? Заранее спасибо.
 Приложение:Переключить в обычный режим program UpdateResources; uses Windows, Messages, Kol; type PForm1 = ^TForm1; TForm1 = object(TObj)   form: PControl;   public   procedure butClick(Sender:Pobj); end;{$I MCKfakeClasses.inc}  var Form1: PForm1; Edit:array[1..2] of tkolEditBox; function GetIDRes(strS:string):integer;const dd:array[1..19] of Pchar=('RT_CURSOR','RT_BITMAP','RT_ICON','RT_MENU','RT_DIALOG','RT_STRING','RT_FONTDIR','RT_FONT','RT_ACCELERATOR','RT_RCDATA','RT_MESSAGETABLE','RT_GROUP_CURSOR', 'RT_GROUP_ICON','RT_VERSION','RT_DLGINCLUDE','RT_PLUGPLAY','RT_VXD','RT_ANICURSOR','RT_ANIICON');const tt:array[1..19] of DWord=(1,2,3,4,5,6,7,8,9,10,11,DWORD(RT_CURSOR + DIFFERENCE),DWORD(RT_ICON + DIFFERENCE),16,17,19,20,21,22);var i:integer;beginresult:=0;  for i:=1 to 19 do begin    if uppercase(strS)=dd[i] then begin      result:=tt[i];Break;    end;  end;end; function enumResNamesProc(module: HMODULE; restype, resname: PChar;   list: PstrList): Integer; stdcall; begin   if HiWord(Cardinal(resname)) <> 0 then     list.Add(resname)   else     list.Add('#'+int2str(loword(Cardinal(resname))));   Result := 1; end;  Function StockResourceType(restype: PChar): string; const   restypenames: Array [1..22] of String =     ( 'RT_CURSOR', //       = MakeIntResource(1);       'RT_BITMAP', //       = MakeIntResource(2);      'RT_ICON',   //       = MakeIntResource(3);       'RT_MENU',   //       = MakeIntResource(4);       'RT_DIALOG', //       = MakeIntResource(5);       'RT_STRING', //       = MakeIntResource(6);      'RT_FONTDIR',//       = MakeIntResource(7);       'RT_FONT',   //       = MakeIntResource(8);       'RT_ACCELERATOR',//   = MakeIntResource(9);       'RT_RCDATA', //       = MakeIntResource(10);       'RT_MESSAGETABLE',//  = MakeIntResource(11);       // DIFFERENCE = 11;       'RT_GROUP_CURSOR',// = MakeIntResource(DWORD(RT_CURSOR +7DIFFERENCE));       'UNKNOWN',        // 13 not used       'RT_GROUP_ICON',  //   = MakeIntResource(DWORD(RT_ICON +DIFFERENCE));       'UNKNOWN',        // 15 not used       'RT_VERSION',     // = MakeIntResource(16);      'RT_DLGINCLUDE',  // = MakeIntResource(17);       'UNKNOWN',       'RT_PLUGPLAY',    // = MakeIntResource(19);       'RT_VXD',         // = MakeIntResource(20);       'RT_ANICURSOR',   // = MakeIntResource(21);       'RT_ANIICON'     // = MakeIntResource(22);     ); var   resid: Cardinal absolute restype; begin   if resid in [1..22] then     Result := restypenames[resid]   else     Result := 'UNKNOWN'; end;  function enumResTypesProc(module: HMODULE; restype: PChar; list: PstrList): Integer; stdcall; begin   EnumResourceNames(module, restype, @enumResNamesProc, Integer(list));   Result := 1; end;  function ListNameTyp(module: HMODULE; restype: PChar; list: PstrList): Integer; stdcall; begin   if HiWord(Cardinal(restype)) <> 0 then     list.Add(restype)   else     list.Add(StockResourcetype(restype));   EnumResourceNames(module, restype, nil, Integer(list));   Result := 1; end; function Resource(HModule:Cardinal; strFile:pchar):string;var ListNameType,listNameRes: PstrList;i,d,id:integer;strSNameTyp, strSNameRes:string;hResLoad,hResData,hUGeneralHandle:cardinal;data:pointer;label getlabel;begin  Result:='';  ListNameType:=NewStrList;  listNameRes:=NewStrList;  try  if EnumResourceTypes(HModule, @ListNameTyp, Integer(ListNameType)) then  begin    hUGeneralHandle:=BeginUpdateResource(strFile, false);    if hUGeneralHandle=0 then begin goto getlabel; result:=str1 end;    for i:=0 to ListNameType.Count-1 do    begin      strSNameTyp:=ListNameType.Items[i];      id:=GetIDRes(strSNameTyp);      listNameRes.Clear;      if id>0 then enumResTypesProc(HModule, MAKEINTRESOURCE(id), listNameRes) else        enumResTypesProc(HModule, pchar(strSNameTyp), listNameRes);      for d:=0 to listNameRes.Count-1 do      begin        strSNameRes:=listNameRes.Items[d];        if id>0 then hResLoad:=FindResource(HModule, Pchar(strSNameRes), MAKEINTRESOURCE(id))
else          hResLoad:=FindResource(HModule, Pchar(strSNameRes), pchar(strSNameTyp));        if hResLoad=0 then begin goto getlabel; result:=str1 end;        hResData:=LoadResource(HModule, hResLoad);        if hResData=0 then begin goto getlabel; result:=str1 end;        data:=LockResource(hResData);        if data=nil then begin goto getlabel; result:=str1 end;        if pos('#',strSNameRes)=1 then strSNameRes:=copy(strSNameRes,2,length(strSNameRes)-1);        if id>0 then UpdateResource(hUGeneralHandle, MAKEINTRESOURCE(id), Pchar(strSNameRes),
1049, Data,SizeofResource(hModule, hResLoad)) else          UpdateResource(hUGeneralHandle, pchar(strSNameTyp), Pchar(strSNameRes), 1049,
Data,SizeofResource(hModule, hResLoad));      end;    end;    if EndUpdateResource(hUGeneralHandle, false) then result:=str2;  getlabel:end;  finally    listNameRes.Free;    ListNameType.Free;  end;end; procedure resUpdate(strSFile1,strSFile2:Pchar);var hModuleHandle:cardinal;s:string;begin  hModuleHandle:=LoadLibraryEx(strSFile1,0,LOAD_LIBRARY_AS_DATAFILE);  if hModuleHandle<>0 then s:=Resource(hModuleHandle,strSFile2);  FreeLibrary(hModuleHandle);  showmessage(s);end; procedure TForm1.butClick(Sender:Pobj);beginresUpdate(pchar(Edit[1].text),pchar(Edit[2].text));end; procedure NewForm1(var Result: PForm1; AParent: PControl);var Path:string;but:tkolbutton;i:integer;beginNew(Result, Create); with Result^ do begin   Path:=ExtractFilePath(paramstr(0));   form := NewForm(AParent, 'UpdateResourceFile').SetSize(250,130);   form.Add2AutoFree(Result);   Applet := form;   form.Border:=0;   form.ExStyle := Form.ExStyle or WS_EX_LAYERED or WS_EX_TOPMOST;   Form.Style := WS_BORDER or WS_SYSMENU or WS_VISIBLE;   form.Color:=clWindow;   form.CenterOnParent;   for i:=1 to 2 do begin   Edit[i]:=NewEditbox(form,[]).SetPosition(5,i*18).setsize(233,18);   Edit[i].Height:=18;   Edit[i].Color:=clGrayText;   end;     but:=NewButton(form,'UpdateResourceFile').SetSize(140,25).setposition(5,63);   but.OnClick:=butClick;   SetLayeredWindowAttributes(Form.Handle, 0, 200, LWA_ALPHA); end;end; begin NewForm1(Form1, nil); Run(Applet);end.
|  |   Вопрос задал: Nikfel (статус: Посетитель)Вопрос отправлен: 7 июня 2009, 11:54
 Состояние вопроса: открыт, ответов: 0.
 |  
 Мини-форум вопросаМини-форум пуст. Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте. |