This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: windres bug with MENUEX resource.


binutils-owner@sourceware.org wrote on 20.04.2007 17:26:40:

> Hi,
> 
> I believe I have found a bug in windres (appears to be part of the
> binutils-20060817-1 package).
> 
> If I define POPUP Submenus of a MENUEX, the resulting resource is
> corrupt.
> 
> I have constructed a small example to show the error:
> 
> | karoshi:~/demo>make
> | windres -i res.rc -o res.o
> | cc -g -O -Wall -mno-cygwin -o demo demo.c res.o 
> | karoshi:~/demo>./demo.exe 
> | LoadMenu failed with error 13: Die Daten sind unzulÃssig.
> 
> (sorry for the german error message, it is "The Data is invalid")
> 
> I have found an (old) mail with a patch for the very same problem. It
> can be viewed at:
> 
> http://sources.redhat.com/ml/binutils/2004-06/msg00609.html
> 
> Unfortunately I don't know how to recompile parts of cygwin, so I can't
> test that patch, but it would be really great if somebody could look at
> this.
> 
> ----------------------------------------------------------------------
> Example resource file "res.rc":
> #include <windows.h>
> 
> 123 MENUEX
> BEGIN
>     POPUP "Dummy", 144
>     BEGIN
>    MENUITEM "&About...", 1
>     END
> END
> ----------------------------------------------------------------------
> Example c program "demo.c":
> #include <stdio.h>
> #include <string.h>
> 
> #include <windows.h>
> 
> void ErrorExit(char *);
> 
> int APIENTRY WinMain(HINSTANCE hInst,
>                      HINSTANCE hPrevInstance,
>                      LPSTR     lpCmdLine,
>                      int       nCmdShow){
> HMENU hCtxMenu;
> 
>         hCtxMenu=LoadMenu (hInst, MAKEINTRESOURCE(123));
>         if(hCtxMenu==NULL){
>             ErrorExit("LoadMenu");
>         };
>         return 0;
> }
> 
> void ErrorExit(char *text) { 
>         TCHAR szBuf[80]; 
>         LPVOID lpMsgBuf;
>         DWORD dw = GetLastError(); 
> 
>         FormatMessage(  FORMAT_MESSAGE_ALLOCATE_BUFFER | 
>                         FORMAT_MESSAGE_FROM_SYSTEM,
>                         NULL,
>                         dw,
>                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
>                         (LPTSTR) &lpMsgBuf,
>                         0, NULL );
>         wsprintf(szBuf, "%s failed with error %d: %s", text, dw, 
lpMsgBuf); 
>         printf("%s",szBuf);
>         LocalFree(lpMsgBuf);
>         ExitProcess(dw); 
> };
> ----------------------------------------------------------------------
> Example Makefile "Makefile":
> CFLAGS+=-g -O -Wall -mno-cygwin
> LIBS=
> 
> PRG=demo
> 
> ${PRG}: ${PRG}.c res.o
>    ${CC} ${CFLAGS} -o ${PRG} ${PRG}.c res.o ${LIBS}
> 
> res.o: res.rc
>    windres -i $< -o $@
> ----------------------------------------------------------------------
> 
> Thanks,
>     Sec
> 
> P.S.: if you remove the ",144" part from the POPUP statement, the
> program will run fine. This is because windres then compiles it as
> "MENU" instead of "MENUEX", which can be verified with "windres -i 
res.o"
> 
> P.P.S.: This is a resend from my posting to the cygwin mailinglist from
> where I was pointed to the binutils mailinglist.

I agree, that the MENUEX resource is not proper.
AFAIC read in the MS specification of rc files, it seems to be that the 
"id" is a dword, as to see in the MENUITEM spec for the "result" field. 
Therefore I assume, that the following patch should be more correct, than 
to simply to pad the structure.

ChangeLog:

2007-04-23  Kai Tietz  <Kai.Tietz@onevision.com>

        * binutils/resbin.c: (bin_to_res_menuexitems,
        res_to_bin_menuexitems): Read id as 32-bit word.




Regards,
 i.A. Kai Tietz

------------------------------------------------------------------------------------------
  OneVision Software Entwicklungs GmbH & Co. KG
  Dr.-Leo-Ritter-StraÃe 9 - 93049 Regensburg
  Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
  Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
  Handelsregister: HRA 6744, Amtsgericht Regensburg
  KomplementÃrin: OneVision Software Entwicklungs Verwaltungs GmbH
  Dr.-Leo-Ritter-StraÃe 9 â 93049 Regensburg
  Handelsregister: HRB 8932, Amtsgericht Regensburg - GeschÃftsfÃhrer: 
Ulrike DÃhler, Manuela Kluger

Attachment: menuitemex_align.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]