我有一个简单的保存文件对话框,我希望将其用作返回文件路径、名称和扩展名的工具。此函数产生运行时错误,表示文件名周围的堆栈已损坏。我希望像这样使用它:
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);
}