i'm fed up with the #$&#$% open dialog

This is a discussion on i'm fed up with the #$&#$% open dialog within the Windows Programming forums, part of the Platform Specific Boards category; When I call GetOpenFileName() the dialog comes up just fine with no errors. And when I hover over a file ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,668

    i'm fed up with the #$&#$% open dialog

    When I call GetOpenFileName() the dialog comes up just fine with no errors.
    And when I hover over a file and the little yellow tool-tip comes there are no problems.
    There are no problems when I click on that file and click OK.
    I can even bring the dialog back up again just fine by calling GetOpenFileName() again.
    But then if I hover over a file, the instant the tool-tip comes up my program terminates!
    I've had this problem before, and I found out that it was only killing my window, and that catching and "return 0;"ing WM_PAINT fixed the problem.
    But this one is different. This one terminates the program right there and then. When I put a Beep(2000,100); right before WinMain()'s return, I don't even hear a beep when is terminates. (that's how I know it terminates, instead of just closes the window.)
    Please help me fix the @#&@**@&@^#& ms windows dialog box.
    Thank you very much for any help you can provide that helps.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    Never encountered such an error. What's the code?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    Yeah - a minimal example that demostrates the problem would get some folks look'n at it (I'm curious myself).

    gg

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,668
    Code:
    BOOL DoOpenDialog(HWND hwnd, char *szDataPath)
    {
       OPENFILENAME ofn;
       ZeroMemory(&ofn, sizeof(ofn));
       ZeroMemory(szDataPath, MAX_PATH);
       ofn.lStructSize = sizeof(ofn);
       ofn.hwndOwner = hwnd;
       ofn.lpstrFilter = "pCrypt Files (*.pc)\0*.pc\0All Files (*.*)\0*.*\0\0";
       ofn.lpstrFile = szDataPath;
       ofn.nMaxFile = MAX_PATH;
       ofn.Flags = OFN_HIDEREADONLY;
       ofn.lpstrTitle = "Open Encryption";
       return GetOpenFileName(&ofn);
    }
    and yes, all my passed varibles are a valid HWND and 260 byte long char string.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,249
    Quote Originally Posted by Yarin View Post
    Code:
    BOOL DoOpenDialog(HWND hwnd, char *szDataPath)
    {
       OPENFILENAME ofn;
       ZeroMemory(&ofn, sizeof(ofn));
       ZeroMemory(szDataPath, MAX_PATH);
       ofn.lStructSize = sizeof(ofn);
       ofn.hwndOwner = hwnd;
       ofn.lpstrFilter = "pCrypt Files (*.pc)\0*.pc\0All Files (*.*)\0*.*\0\0";
       ofn.lpstrFile = szDataPath;
       ofn.nMaxFile = MAX_PATH;
       ofn.Flags = OFN_HIDEREADONLY;
       ofn.lpstrTitle = "Open Encryption";
       return GetOpenFileName(&ofn);
    }
    Potential overflow on the ZeroMemory(szDataPath, MAX_PATH) call. What if szDataPath doesn't point to a memory block of at least MAX_PATH+1 bytes? You will corrupt memory in that case.

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,668
    Code:
                char szfilename[MAX_PATH];
                if(!DoOpenDialog(hwnd, szfilename)) return 0;
                char *buff = OpenCryption(hwnd, szfilename);
                if(!buff) {
                   MessageBox(hwnd, BAD_OPEN_TEXT, MB_TITLE, MB_ICONWARNING);
                   return 0;   }
                SetWindowText(window[0], buff);
                delete [] buff;
                SetFocus(window[0]);
    here is where it's called from.

    EDIT:
    Potential overflow on the ZeroMemory(szDataPath, MAX_PATH) call. What if szDataPath doesn't point to a memory block of at least MAX_PATH+1 bytes? You will corrupt memory in that case.
    I don't get it, are you saying ZeroMemory(pointer, 0) would actually set pointer[0] to null!?
    Last edited by Yarin; 01-30-2008 at 09:28 PM.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I do believe it's not necessary to fill the entire path with zero, but I don't see any reason why it shouldn't work like that. ZeroMemory takes the number of bytes to clear, that's for sure, and it's the right value.

    Another thought of course, is to pass in the size of the path variable to the function, that way you don't have to worry about it's size.

    I'm not a Windows API programmer, so I can't say what may be wrong tho'.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    As matsp said, pass in the size of szDataPath just to be safe -- and check it in DoOpenDialog. That way you'll explictly have to mention it's size.

    Code:
    BOOL DoOpenDialog(HWND hwnd, char * szDataPath, size_t szDataPathSize);
    
    /* ... */
    
    char path[255];
    DoOpenDialog(GetDesktopWindow(), path, sizeof(path));
    Ta-da

    As for the other problem, use a debugger.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    Yes, I'm all for the idea too, since GetOpenFileName isn't limited to MAX_PATH size. If you sometime want to be able to select multiple files, you'll find MAX_PATH to be a little conservative.
    Here's what's different between your code and MFC's OpenFileDialog that I could see:

    - ofn {lStructSize=88 hwndOwner=0x00000000 hInstance=0x00000000 ...} tagOFNA
    + hInstance 0x00000000 {unused=??? } HINSTANCE__ *
    + lpstrFileTitle 0x00000000 <Bad Ptr> char *
    nMaxFileTitle 0 unsigned long
    + lpstrTitle 0x0042896c "Open Encryption" const char *
    Flags 4 unsigned long
    + lpstrDefExt 0x00000000 <Bad Ptr> const char *
    lpfnHook 0x00000000 unsigned int (HWND__ *, unsigned int, unsigned int, long)*


    - m_pOFN 0x00038b58 {lStructSize=88 hwndOwner=0x00000000 hInstance=0x00400000 ...} tagOFNA *
    + hInstance 0x00400000 {unused=9460301 } HINSTANCE__ *
    + lpstrFileTitle 0x0013f860 "" char *
    nMaxFileTitle 64 unsigned long
    Flags 530468 unsigned long
    + lpstrDefExt 0x00038b18 "*.*" const char *
    lpfnHook 0x786854e0 _AfxCommDlgProc(HWND__ *, unsigned int, unsigned int, long) unsigned int (HWND__ *, unsigned int, unsigned int, long)*

    The flags I use are OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY.
    Don't know if it helps.
    Last edited by Elysia; 01-31-2008 at 04:15 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,668
    >> Don't know if it helps.
    Sorry, no. I don't know how it would?

    I changed the function to get the size, on top of that, when I call it I say the string is 1 less than it really is. (to what you've been saying) But the problem still remains as I knew it would. The problem has to do with the yellow tool-tip that pops up when you hover over a file. It has nothing to do with the path string.

    >> As for the other problem, use a debugger.
    I don't know how to use the debugger, and even if I did, how would it help. the program just dies.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    It could because with MFC I don't encounter your problem to my knowledge.
    But even your example works fine for me.
    Last edited by Elysia; 01-31-2008 at 09:25 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    The larch
    Join Date
    May 2006
    Posts
    3,573
    When I use your function in a program like this I get no problems.

    Code:
    int main()
    {
        while (1) {
            char szfilename[MAX_PATH];
            if(!DoOpenDialog(0, szfilename)) return 0;
        }
    }
    Perhaps there are problems elsewhere in the program?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    Indeed, even with a dialog it works fine:

    Code:
    	char buf[MAX_PATH];
    	CMyDialog dlg;
    	dlg.Create(IDD_DIALOG1);
    
    	for (int i = 0; i < 10; i++)
    	{
    		DoOpenDialog(dlg.m_hWnd, buf);
    	}
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,668
    >> But even your example works fine for me.
    and
    >> Indeed, even with a dialog it works fine:

    I see. Would you be willing load my exe and try it?
    If so...

    Below (I think) you should see the file pCrypt.zip.pdf. save it and get rid of the .pdf on the end. Open the zip and you will see an exe. Open the exe and there will be a load button. Click it, and the Open dialog pops up. Create a file with the extention .pc and hover your cursor over it until the little yellow tool-tip comes up. When it does, close the open dialog, then click on the load button again. hover over the same file, within seconds when the tool-tip normaly pops back up, the program will totally end.
    Attached Images Attached Images
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    Doesn't happen...
    Works as you would expect it would.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 02:18 PM
  2. Splitting a dialog up into multiple classes
    By Just in forum Windows Programming
    Replies: 1
    Last Post: 05-29-2005, 11:11 PM
  3. open a file browser from a win32 dialog
    By jcorrington in forum Windows Programming
    Replies: 4
    Last Post: 11-10-2004, 06:28 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21