Hello ,I'm writing a GUI with C Win32 API and facing following issue. When I start the program and click the button for Opening the file dialog everything works fine. I can choose a file and all informations seem to fit properly into the ofn structure.

If I choose to click the button a second time without doing something else everything works fine again.

If i start my algorithm after choosing a file and wait untill it's finished i cannot choose another file. Everytime i try the program runs until the call to GetOpenFileName(&ofn) and freezes while executing this function.

The only issue i can imagine is within the HWND which is saved into ofn.hwndOwner, but i checked. Everytime the function is called the provided value for HWND is same. Moreover the GetOpenFileName function gets called by the window procedure callback function which supplies the value for HWND. Heres the code for the function which calls GetOpenFileName.

Any help would be appreciated.

LPSTR OpenFileDialog(HWND hwnd_t) {

   OPENFILENAME ofn;
   TCHAR szFile[MAX_PATH];

   ZeroMemory(&ofn, sizeof(ofn));

   ofn.lStructSize = sizeof(ofn);
   ofn.lpstrFile = szFile;
   ofn.lpstrFile[0] = '\0';
   ofn.hwndOwner = hwnd_t;
   ofn.nMaxFile = sizeof(szFile);
   ofn.lpstrFilter = TEXT("All files(*.*)\0*.*\0\0");
   ofn.nFilterIndex = 1;
   ofn.lpstrInitialDir = "D:\\casdev\\";
   ofn.lpstrFileTitle = NULL;
   ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR;

   if (GetOpenFileName(&ofn))
   {

      return ofn.lpstrFile;

   }
   else return "";

}

Recommended Answers

All 4 Replies

I can't tell if you did research on this. Example:
https://www.google.com/search?q=GetOpenFileName+freezes+at+second+execution&ie=utf-8&oe=utf-8

The first hit is about turning off DEP for your app. I have a theory why that happens but it would be machine specific since I can't guess what else is on this PC, well I can't tell you it's "xviewer version 12" or something else. As you know this file open does a lot more than most suspect.

Problem solved... during execution of the algorithm the current working directory was somehow changed. Restoring it to the original value before executing GetOpenFileName solved the problem.

I appreciate your help.

Just to complete your post so all may know. What changes the current working directory? I can navigate in the dialog box so there is that.
Was it that or something in your code?

Unfortunatly problem wasnt solved...what i wrote above about change of working directory was correct but actualy not the cause of my problem...needed a while to discover that.

Some details about the problem changed, so i decided to open up a new thread about it, which you can find here: Click Here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.