Thread: GetOpenFileName

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    167

    GetOpenFileName

    This works

    Code:
     
            if (int retval = GetOpenFileName(&ofn)){
              pe.Map(openFileName );
              pe.IsValid();
              pe.UnMap();
            }
    but this doesn't

    Code:
     
            if (GetOpenFileName(&ofn)){
              pe.Map(openFileName );
              pe.IsValid();
              pe.UnMap();
            }
    Why?
    silk.odyssey

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    what do you mean it doesn't work?

    theoretically those both work the same way....

    here's a clearer example:

    Code:
     if(int a=1)
        cout << "blah" << endl;
     if(1)
        cout << "blah 22";
    in the first example, it does the following:

    1) creates the variable a, as an int
    2) assigns a to 1
    3) tests the value of a, which is 1, therefor becoming true, and outputting blah

    in the second one, it does this:

    1) tests if 1...is true...duh
    2) outputs blah 22

    so i don't see how your code above could be "not working" but i also don't know what you mean by "not working"

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    17
    silk.odyssey, In the first code you posted it is allways true, but in the 2nd one GetOpenFileName, has a chance of being 0.

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Not necessarily true hollowlife, notice that it's not testing if GetOpenFileName was assigned correctly to the variable, but that it's actually testing the result of what's in the variable after the assignment operation.

    Here's a test i did to show what i mean:

    Code:
     #include <iostream.h>
     
     int func(int test)
     {
     	return test;
     }
     
     int main()
     {
     	if(int a=func(1))	// Evaluates to 1, so it's true
     		cout << "yo";
     	if(int a=func(0))	// Evaluates to 0, so it's false
     		cout << "yo 2";
     	return 0;
     }
    the output from this program is:

    yo

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    17
    Hmm, I could of swore that was what caused a bug with one of my programs, but just ignore my last post.

  6. #6
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    I've figured out what my problem was. The ofn structure and the fileName buffer were declared on the stack.I zeroed the ofn structure but didn't bother to do that with the filename thinking that whatever was there would be over written. However it seems that the GetOpenFileName function requires that the filename buffer be initialized to zero because after I did that it fixed the probem that I posted and another one where the dialog was not shown if the window was maximized or too close to the top left corner of the screen. Mysteries of windows programming?
    silk.odyssey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetOpenFileName not working...
    By manugarciac in forum Windows Programming
    Replies: 6
    Last Post: 04-24-2007, 10:50 PM
  2. GetOpenFileName function for dir's?
    By willc0de4food in forum Windows Programming
    Replies: 3
    Last Post: 04-15-2006, 12:54 AM
  3. Major Problems with GetSaveFileName() and GetOpenFileName()
    By CodeHacker in forum Windows Programming
    Replies: 8
    Last Post: 07-12-2004, 11:05 AM
  4. Troubles with GetOpenFileName()
    By lyx in forum Windows Programming
    Replies: 13
    Last Post: 10-28-2003, 09:47 PM
  5. GetOpenFileName() won't show
    By harryP in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2003, 04:47 PM