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 "";

}

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