在网上查了些资料,说用BeginUpdateResource、UpdateResource、EndUpdateResource这三个函数可以实现修改EXE文件的版本信息,我不会弄,请高手指教。这里还有个类似的例子:function   TFormMain.ReplaceMediaRes(SrcFileName:String;MediaFileName:String):Boolean;   
  var   
      fs:TFileStream;   
      buffer:PChar;   
      hUpdateRes:THandle;   
  begin   
      result:=false;   
      if   not   FileExists(SrcFileName)   then   begin   
          MessageBox(Handle,pchar(SrcFileName+'   not   exists.'),pchar(Application.Title),MB_ICONERROR);   
          exit;   
      end;   
      if   not   (FileExists(MediaFileName))   then   begin   
          MessageBox(Handle,pchar(MediaFileName+'   not   exists.'),pchar(Application.Title),MB_ICONERROR);   
          exit;   
      end;   
      fs:=TFileStream.Create(MediaFileName,fmOpenReadWrite);   
      try   
          GetMem(buffer,fs.size);   
          try   
              fs.ReadBuffer(buffer^,fs.size);   
              //begin   update   resource   
              hUpdateRes:=BeginUpdateResource(pchar(SrcFileName),false);   
              if(hUpdateRes=0)   then   begin   
                  MessageBox(Handle,pchar('Error   to   begin   update   resource.'),pchar(Application.Title),MB_ICONERROR);   
                  exit;   
              end;   
              //!!   the   language   id   can   get   with   GetUserDefaultLangID(),   in   english   system   it's   1033.   
              result:=UpdateResource(hUpdateRes,pchar('PLAYER'),pchar('MEDIA'),1033,buffer,fs.Size);   
              if   not   result   then   begin   
                  MessageBox(Handle,pchar('Error   ro   update   resource'),pchar(Application.Title),MB_ICONERROR);   
                  exit;   
              end;   
              if   not   EndUpdateResource(hUpdateRes,false)   then   begin   
                  MessageBox(Handle,pchar('Error   to   end   update   resource.'),pchar(Application.Title),MB_ICONERROR);   
                  exit;   
              end;   
          finally   
              FreeMem(buffer);   
          end;   
      finally   
          fs.Free;   
      end;   
      result:=true;   
  end;   

解决方案 »

  1.   

    我找到了1份VC的,哪位高手能帮我写成DELPHI的吗?谢谢了!!!  hResource   =   BeginUpdateResource(lpszFile,   FALSE);   
                              if   (NULL   !=   hResource)   
      {   
      UINT   uTemp;   
        
      TCHAR strSubBlock[256];   
      LPTSTR     pValueBuffer;   
        
      _stprintf(strSubBlock,   _T("\\StringFileInfo\\%04x%04x\\CompanyName"),   
                                            lpTranslate->wLanguage,     
                                            lpTranslate->wCodePage);   
        
      if   (VerQueryValue(lpBuffer,   (LPTSTR)   ((LPCTSTR)   strSubBlock),   (LPVOID   *)   &pValueBuffer,   &uTemp)   !=   FALSE)   
      {   
      _tcscpy(pValueBuffer,   _T("My   Corp"));   
        
      if   (UpdateResource(hResource,   RT_VERSION,   MAKEINTRESOURCE(VS_VERSION_INFO),   lpTranslate->wLanguage,   lpBuffer,   dwSize)   !=   FALSE)   
                                              {   
                                                      if   (EndUpdateResource(hResource,   FALSE)   ==   FALSE)   
                                                              dwResult   =   GetLastError();   
                                              }   
                                              else   
                                                      dwResult   =   GetLastError();   
      }   
        
      }