我有一個簡單的保存文件對話框,我想用它作爲工具返回文件路徑,名稱和擴展名。這個函數產生一個運行時錯誤,說文件名周圍的堆棧已損壞。我希望像這樣使用它:從文件保存對話框返回文件名(windows32)
wchar_t filename[] = L"";
newGradebookDialog(hwnd, filename);
這裏是我的功能。它修改文件名,因爲我期望它,但運行時堆棧錯誤是我沒有得到。
void newGradebookDialog(HWND hwnd, wchar_t file[])
{
OPENFILENAME ofn;
wchar_t saveFileName[MAX_PATH] = L"";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = L"Database File (*.db)\0*.db\0";
ofn.lpstrFile = saveFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrDefExt = L"db";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrTitle = L"Save New Database";
if(GetSaveFileName(&ofn))
wcscpy(file,saveFileName);
}