M
Das Beispiel aus MSDN
http://msdn.microsoft.com/en-us/library/ms646829(v=vs.85).aspx#open_file
mit VS2010 als Konsolenanwendung kompiliert scheint mit sehr geringen Anpassungen zu laufen.
// OpenFile.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
#include <windows.h>
#include "stdafx.h"
#pragma comment(lib, "Comdlg32")
int _tmain(int argc, _TCHAR* argv[])
{
OPENFILENAME ofn; // common dialog box structure
TCHAR szFile[260]; // buffer for file name
HWND hwnd = NULL; // owner window, can be NULL if the dialog box has no owner
HANDLE hf; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = _T("All\0*.*\0Text\0*.TXT\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box.
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile, GENERIC_READ, 0,
(LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
return 0;
}