X-Spam-Check-By: sourceware.org Date: Fri, 20 Apr 2007 17:03:18 +0200 From: Stefan `Sec` Zehl To: cygwin AT cygwin DOT com Subject: windres bug with MENUEX resource. Message-ID: <20070420150318.GA96830@ice.42.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.4.2.2i I-love-doing-this: really X-Modeline: vim:set ts=8 sw=4 smarttab tw=72 si noic notitle: Accept-Languages: de, en X-URL: http://sec.42.org/ Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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 123 MENUEX BEGIN POPUP "Dummy", 144 BEGIN MENUITEM "&About...", 1 END END ---------------------------------------------------------------------- Example c program "demo.c": #include #include #include 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" -- The most successful method of programming is to begin a program as simply as possible, test it, and then add to the program until it performs the required job." -- PDP8 handbook, Pg 9-64 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/