0

I have a problem with GetOpenFileName. Before calling GetOpenFileName method WriteData is working. WriteData have a simple file check procedure:

ifstream inFile(FileName.c_str());
if (!inFile.is_open()) return false;

ofn dump: Dump
And after calling GetOpenFileName its always false. But before calling GetOpenFileName its working fine.

while (!lang->LoadLang(config->getLanguagePath()))
{
    OPENFILENAME ofn = {0};
    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFile = config->getLanguagePath();
    ofn.lpstrFile[0] = '\0';
    ofn.lpstrTitle = "Select the language file";
    ofn.nMaxFile = 255;
    ofn.lpstrFilter = "Language file\0*.lng\0";
    ofn.nFilterIndex = 1;
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    if (GetOpenFileName(&ofn) == 0) return 0;
    config->WriteData(KEY_LANG, ofn.lpstrFile);
}
Dmitry K.
  • 3,065
  • 2
  • 21
  • 32

1 Answers1

0

Problem solved. I tried to use WinAPI function OpenFile to open file, and got error code 2 (file not found). And now i fixed it.

char buffer[255];
GetCurrentDirectoryA(255, buffer);
OPENFILENAME ofn = {0};
ofn.hInstance = hInstance;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFile = config->getLanguagePath();
ofn.lpstrFile[0] = '\0';
ofn.lpstrTitle = "Select the language file";
ofn.nMaxFile = 255;
ofn.lpstrFilter = "Language file\0*.lng\0";
ofn.nFilterIndex = 1;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn) == 0) return 0;
SetCurrentDirectory(buffer);
config->WriteData(KEY_LANG, ofn.lpstrFile);
Dmitry K.
  • 3,065
  • 2
  • 21
  • 32