The current version of the Windows API documentation of the OPENFILENAME
structure states (emphasis mine):
lpstrDefExt
Type:LPCTSTR
The default extension.
GetOpenFileName
andGetSaveFileName
append this extension to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member isNULL
and the user fails to type an extension, no extension is appended.
This is incorrect, as executing the following MVCE on Windows 10 (Build 17134.5) shows:
#include <stdio.h>
#include <Windows.h>
int main()
{
wchar_t filename[256] = { 0 };
OPENFILENAMEW ofn =
{
.lStructSize = sizeof(OPENFILENAMEW),
.lpstrFilter = L"All Files\0*.*\0\0",
.lpstrFile = filename,
.nMaxFile = sizeof(filename),
.lpstrDefExt = L"xlsx"
};
BOOL ret = GetSaveFileNameW(&ofn);
if (ret != 0)
{
wprintf(L"%s\r\n", filename);
}
}
Entering test
in the Save File dialog box yields C:\Users\...\Documents\test.xlsx
, not C:\Users\...\Documents\test.xls
, as the documentation claims.
When did this change, i.e., on which target systems can I rely on lpstrDefExt
supporting more than three characters?