Here's the code using GetOpenFileNameW:
import core.sys.windows.windows;
import std.stdio, std.string, std.utf;
pragma(lib, "comdlg32");
extern (Windows) DWORD CommDlgExtendedError();
enum OFN_FILEMUSTEXIST = 0x001000;
void main()
{
auto buf = new wchar[1024];
OPENFILENAMEW ofn;
ofn.lStructSize = ofn.sizeof;
ofn.lpstrFile = buf.ptr;
ofn.nMaxFile = buf.length;
ofn.lpstrInitialDir = null;
ofn.Flags = OFN_FILEMUSTEXIST;
BOOL retval = GetOpenFileNameW(&ofn);
if (retval == 0) {
throw new Exception(format("GetOpenFileName failure: 0x%04X.", CommDlgExtendedError()));
}
writeln(buf);
}
This leads to FNERR_INVALIDFILENAME, but I do not see any optional lines that I did not fill out. And here is the code (only differences) for GetOpenFileNameA:
auto buf = new char[1024];
OPENFILENAMEA ofn;
BOOL retval = GetOpenFileNameA(&ofn);
The result is CDERR_INITIALIZATION, and the only MSDN development gives me
The common dialog box function failed during initialization.
This error often occurs when sufficient memory is not available.
This is for Windows 7 64 bit, DMD v2.059.
source
share