From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#13065: Bug in x-file-dialog with GetOpenFileName Date: Tue, 15 Jan 2013 20:03:24 +0200 Message-ID: <83wqve8gsz.fsf@gnu.org> References: <83liddr5u8.fsf@gnu.org> <87pq1fhlbo.fsf@gnu.org> <83r4lvgydf.fsf@gnu.org> <87fw251bzq.fsf@gnu.org> <83boctrqg2.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1358273017 8586 80.91.229.3 (15 Jan 2013 18:03:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Jan 2013 18:03:37 +0000 (UTC) Cc: 13065@debbugs.gnu.org, duyanning@gmail.com To: jasonr@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 15 19:03:54 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TvAra-0005XR-Mo for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 Jan 2013 19:03:54 +0100 Original-Received: from localhost ([::1]:41846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvArJ-0006LR-Pq for geb-bug-gnu-emacs@m.gmane.org; Tue, 15 Jan 2013 13:03:37 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:51267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvArF-0006Jx-Qu for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2013 13:03:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvArE-0003HJ-Eg for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2013 13:03:33 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56453) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvArE-0003HD-Bg for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2013 13:03:32 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TvAri-0004kf-Fx for bug-gnu-emacs@gnu.org; Tue, 15 Jan 2013 13:04:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 15 Jan 2013 18:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13065 X-GNU-PR-Package: emacs,w32 X-GNU-PR-Keywords: Original-Received: via spool by 13065-submit@debbugs.gnu.org id=B13065.135827301618230 (code B ref 13065); Tue, 15 Jan 2013 18:04:02 +0000 Original-Received: (at 13065) by debbugs.gnu.org; 15 Jan 2013 18:03:36 +0000 Original-Received: from localhost ([127.0.0.1]:33684 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TvArH-0004jz-GS for submit@debbugs.gnu.org; Tue, 15 Jan 2013 13:03:35 -0500 Original-Received: from mtaout20.012.net.il ([80.179.55.166]:47769) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TvArD-0004jk-Om for 13065@debbugs.gnu.org; Tue, 15 Jan 2013 13:03:33 -0500 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0MGO00400I1Z2500@a-mtaout20.012.net.il> for 13065@debbugs.gnu.org; Tue, 15 Jan 2013 20:02:55 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MGO003FLI4UOXC0@a-mtaout20.012.net.il>; Tue, 15 Jan 2013 20:02:55 +0200 (IST) In-reply-to: <83boctrqg2.fsf@gnu.org> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:69819 Archived-At: > Date: Sun, 13 Jan 2013 18:35:41 +0200 > From: Eli Zaretskii > Cc: 13065@debbugs.gnu.org, duyanning@gmail.com > > > From: Jason Rumney > > Cc: duyanning@gmail.com, 13065@debbugs.gnu.org > > Date: Sun, 13 Jan 2013 20:52:25 +0800 > > > > Eli Zaretskii writes: > > > > >> Is it not just a case of doing the same as we did previously? > > >> > > >> /* If we compile with _WIN32_WINNT set to 0x0400 (for NT4 > > >> compatibility) we end up with the old file dialogs. Define a big > > >> enough struct for the new dialog to trick GetOpenFileName into > > >> giving us the new dialogs on newer versions of Windows. */ > > > > > > Sorry, I don't understand: we still do what the above comment > > > describes. > > > > I meant maybe we need to increase the size of the struct again to fool > > Windows 7 into thinking we are compiling against a more recent version > > of the SDK. > > Thanks, will try that some time soon. I spent some more time tinkering with this. First, the new Windows 7 dialogs are not merely an extension of the old ones, they are an entirely different implementation, via COM objects and a C++ interface. They also don't accept a structure similar to OPENFILENAME. So the trick to expand the structure is not going to help us. > > c) The filter string uses some "*|*" magic in the directory filter, > > which doesn't seem to be documented anywhere. What does it do? > > Nothing. It has to be different than the *.* that is used for normal > file selection, but couldn't be simply * IIRC. The magic is in the > callback function and the code that strips away the filename when the > dialog call has finished if the "Directories" option is selected. > > But in this report, the Directory filter was never chosen, so I don't > think it is related. You could try removing the Directories portion of > the filter string and the callback to be sure. Tried without the Directories portion, didn't help. I tried to attack this from a different angle. I compiled a simple stand-alone program (source below) that just opens the file selector dialog and prints the selected name after you click Open. This program works fine both on XP and on Windows 7, and shows a dialog that is almost exactly the same as what Emacs displays -- the only difference, which only shows on Windows 7, is in the slightly different visual appearance of the "Open" and "Cancel" buttons (on XP the dialog is identical to what Emacs shows, including the buttons). (To show dialogs like Emacs does, compile the program with the "-D_WIN32_WINNT=0x0501" switch, otherwise you get old-style dialogs.) Then I examined the Emacs sources for any differences between how we set up the dialog and this sample program, and modified the Emacs source to exactly match the sample program, right down to use of ZeroMemory instead of memset (ridiculous, I know; but I was desperate). Nothing helped: the same code in Emacs still won't close the dialog and return the file name, unless I select an existing file. By contrast, the sample program below will return any file name, whether or not that file exists, in any directory. Maybe I'm blind and missed some difference that I didn't eliminate. You are welcome to try that experiment and see if you succeed where I failed. Failing that, I'm beginning to think that the problem is elsewhere in Emacs. But what could that be? Is it possible that one of our message pumps somehow interferes with the dialog interaction, e.g., by intercepting some of the messages that were supposed to wind up in our hook procedure? Could it be due to the fact that our main message pump uses Unicode APIs, while the file selector uses ANSI APIs? Something else? I'm stumped. Here's the program to try: #include #include static UINT_PTR CALLBACK file_dialog_callback (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { return 0; } int main (void) { OPENFILENAMEA ofn; // common dialog box structure char szFile[260]; // buffer for file name // Initialize OPENFILENAME ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = NULL; ofn.lpstrFile = szFile; // Set lpstrFile[0] to '\0' so that GetOpenFileName does not // use the contents of szFile to initialize itself. ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = (OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_EXPLORER | OFN_ENABLEHOOK); ofn.lpfnHook = file_dialog_callback; // Display the Open dialog box. if (GetOpenFileNameA(&ofn)==TRUE) printf ("GetOpenFile: '%s'\n", ofn.lpstrFile); else printf ("Failure: 0x%x\n", (unsigned)CommDlgExtendedError ()); return 0; }