This works
but this doesn'tCode:if (int retval = GetOpenFileName(&ofn)){ pe.Map(openFileName ); pe.IsValid(); pe.UnMap(); }
Why?Code:if (GetOpenFileName(&ofn)){ pe.Map(openFileName ); pe.IsValid(); pe.UnMap(); }
This works
but this doesn'tCode:if (int retval = GetOpenFileName(&ofn)){ pe.Map(openFileName ); pe.IsValid(); pe.UnMap(); }
Why?Code:if (GetOpenFileName(&ofn)){ pe.Map(openFileName ); pe.IsValid(); pe.UnMap(); }
silk.odyssey
what do you mean it doesn't work?
theoretically those both work the same way....
here's a clearer example:
in the first example, it does the following:Code:if(int a=1) cout << "blah" << endl; if(1) cout << "blah 22";
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"
silk.odyssey, In the first code you posted it is allways true, but in the 2nd one GetOpenFileName, has a chance of being 0.
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:
the output from this program is: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; }
yo
Hmm, I could of swore that was what caused a bug with one of my programs, but just ignore my last post.
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