我遇到GetOpenFileName问题。 在调用GetOpenFileName方法之前,WriteData正在运行。 WriteData有一个简单的文件检查程序:
ifstream inFile(FileName.c_str());
if (!inFile.is_open()) return false;
ofn dump:
在调用GetOpenFileName之后,它始终为false。但在调用GetOpenFileName之前它的工作正常。
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);
}
答案 0 :(得分:0)
问题解决了。我尝试使用WinAPI函数OpenFile打开文件,并得到错误代码2(找不到文件)。 现在我修好了。
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);