0

GetOpenFileName 有问题。在调用 GetOpenFileName 方法之前,WriteData 正在工作。WriteData 有一个简单的文件检查程序:

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

ofn 转储: 倾倒
并且在调用 GetOpenFileName 后它总是错误的。但在调用 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);
}
4

1 回答 1

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);
于 2013-11-23T05:39:12.173 回答