Skip to main content
GameDev.net gamedev.net
🔒 Locked

Code works with SP2 but not without

Started by Ainokea May 14, 2005 at 1:43 AM 2 replies 1.3k views
Original Post
Ainokea
Ainokea
Me and a friend are making a map editor and I wrote some code so that you can save maps but it doesnt work on his computer or my other friends computer. Neither of which have SP2. I tried it on my computer (Windows XP with SP2) and some school computers (Windows 98) and it works. Just in case this is important, I am using some win32 code to pop open the save and load dialog but the app is mostly SDL. Though I think it should work because SDL's windowing code is just a wrapper around Win32. Anyway, here is the source:

    if((keys[SDLK_LCTRL]&&keys[SDLK_s])||(keys[SDLK_RCTRL]&&keys[SDLK_s]))
    {
        OPENFILENAME ofn;
        char szFileName[MAX_PATHY];

        ZeroMemory(&ofn, sizeof(ofn));

        ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
        ofn.lpstrFilter = "Wak Files (*.wak)\0*.wak\0All Files (*.*)\0*.*\0";
        ofn.lpstrFile = szFileName;
        ofn.nMaxFile = MAX_PATH;
        ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
        ofn.lpstrDefExt = "wak";

        if(GetOpenFileName(&ofn))
        {
            mappy.Save(szFileName); 
        }
    }

______________With the flesh of a cow.
Drew_Benton
Drew_Benton
That's really odd. On the MSDN page for GetOpenFileName it says:
Quote:
Windows 95/98/Me: GetOpenFileNameW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.


I'm not sure why that works on 98 fine and not on XP without a SP2 installed. What is your MAX_PATHY defined as? (Supposed to be MAX_PATH?) Also can you try to compile on a non-sp2 machine and test again?

Also according to this page:
Quote:
create an old-style dialog box that replaces the default dialog box.
lpstrFilter
Pointer to a buffer containing pairs of null-terminated filter strings. The last string in the buffer must be terminated by two NULL characters.

The first string in each pair is a display string that describes the filter (for example, "Text Files"), and the second string specifies the filter pattern (for example, "*.TXT"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.TXT;*.DOC;*.BAK"). A pattern string can be a combination of valid file name characters and the asterisk (*) wildcard character. Do not include spaces in the pattern string.

The system does not change the order of the filters. It displays them in the File Types combo box in the order specified in lpstrFilter.

If lpstrFilter is NULL, the dialog box does not display any filters.

Windows XP: In the case of a shortcut, if no filter is set, GetOpenFileName and GetSaveFileName retrieve the name of the .lnk file, not its target. This behavior is the same as setting the OFN_NODEREFERENCELINKS flag in the Flags member. To retrieve a shortcut's target without filtering, use the string "All Files\0*.*\0\0".


You need to have:
ofn.lpstrFilter = "Wak Files (*.wak)\0*.wak\0All Files (*.*)\0*.*\0\0";
Ainokea
Ainokea
Quote:
Original post by Drew_Benton
That's really odd. On the MSDN page for GetOpenFileName it says:
Quote:
Windows 95/98/Me: GetOpenFileNameW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.


I'm not sure why that works on 98 fine and not on XP without a SP2 installed. What is your MAX_PATHY defined as? Also can you try to compile on a non-sp2 machine and test again?

MAX_PATHY is 256. And it has been compiled on my friends computer.
The problem isn't with GetOpenFileName AFAIK because it doesn't even pop up the file browser dialog.

______________With the flesh of a cow.
Drew_Benton
Drew_Benton
Looking though the docs some more, you will also need to have (when you go to release mode at least):
char szFileName[MAX_PATHY];memset(szFileName,0,MAX_PATHY);

Quote:
lpstrFile
Pointer to a buffer that contains a file name used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns successfully, this buffer contains the drive designator, path, file name, and extension of the selected file.


Other than that, do you know where it fails in the function?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.