Here's the code I use, Paul. It's VBA code, not C++, but you may be able to
extract the info you need from it. It has all the flags, and works correctly
on Windows 2000 and Windows XP (thanks to some help from fellow Access MVP
Stephen Lebans). Excuse the copyright and disclaimer, I don't usually
include those in newsgroup postings, I added them to this code when I
published it on a web page.
The first two groups of constants are my own constants, used for error
handling. The API flags are those beginning with 'OFN_', 'CDERR_' and
'FNERR_'
'Copyright (C) 2002 Brendan Reynolds
'
http://brenreyn.brinkster.net
'
'You have a royalty-free right to use, modify, reproduce and
'distribute this code (and/or any modified version) in any way
'you find useful, provided that you agree that Brendan Reynolds
'has no warranty, obligations or liability for this code.
Option Compare Database
Option Explicit
Private Const mlngcFirstError As Long = 19581
Private Const mlngcUserCancelled As Long = mlngcFirstError + vbObjectError +
0
Private Const mlngcDialogFailure As Long = mlngcFirstError + vbObjectError +
1
Private Const mlngcStructSize As Long = mlngcFirstError + vbObjectError + 2
Private Const mlngcInitialization As Long = mlngcFirstError + vbObjectError
+ 3
Private Const mlngcNoTemplate As Long = mlngcFirstError + vbObjectError + 4
Private Const mlngcNoHInstance As Long = mlngcFirstError + vbObjectError + 5
Private Const mlngcLoadStrFailure As Long = mlngcFirstError + vbObjectError
+ 6
Private Const mlngcFindResFailure As Long = mlngcFirstError + vbObjectError
+ 7
Private Const mlngcLoadResFailure As Long = mlngcFirstError + vbObjectError
+ 8
Private Const mlngcLockResFailure As Long = mlngcFirstError + vbObjectError
+ 9
Private Const mlngcMemAllocFailure As Long = mlngcFirstError + vbObjectError
+ 10
Private Const mlngcMemLockFailure As Long = mlngcFirstError + vbObjectError
+ 11
Private Const mlngcNoHook As Long = mlngcFirstError + vbObjectError + 12
Private Const mlngcRegisterMsgFail As Long = mlngcFirstError + vbObjectError
+ 13
Private Const mlngcSubClassFailure As Long = mlngcFirstError + vbObjectError
+ 14
Private Const mlngcInvalidFileName As Long = mlngcFirstError + vbObjectError
+ 15
Private Const mlngcBufferTooSmall As Long = mlngcFirstError + vbObjectError
+ 16
Private Const mstrcUserCancelled As String = "User cancelled."
Private Const mstrcDialogFailure As String = "Dialog failure."
Private Const mstrcStructSize As String = "Struct size."
Private Const mstrcInitialization As String = "Initialization."
Private Const mstrcNoTemplate As String = "No template."
Private Const mstrcNoHInstance As String = "No instance."
Private Const mstrcLoadStrFailure As String = "Load str failure."
Private Const mstrcFindResFailure As String = "Find res failure."
Private Const mstrcLoadResFailure As String = "Load res failure."
Private Const mstrcLockResFailure As String = "Lock res failure."
Private Const mstrcMemAllocFailure As String = "Mem alloc failure."
Private Const mstrcMemLockFailure As String = "Mem lock failure."
Private Const mstrcNoHook As String = "No hook."
Private Const mstrcRegisterMsgFail As String = "Register msg fail."
Private Const mstrcSubClassFailure As String = "Sub class failure."
Private Const mstrcInvalidFileName As String = "Invalid file name."
Private Const mstrcBufferTooSmall As String = "Buffer too small."
Private Const OFN_READONLY As Long = &H1&
Private Const OFN_OVERWRITEPROMPT As Long = &H2&
Private Const OFN_HIDEREADONLY As Long = &H4&
Private Const OFN_NOCHANGEDIR As Long = &H8&
Private Const OFN_SHOWHELP As Long = &H10&
Private Const OFN_ENABLEHOOK As Long = &H20&
Private Const OFN_ENABLETEMPLATE As Long = &H40&
Private Const OFN_ENABLETEMPLATEHANDLE As Long = &H80&
Private Const OFN_NOVALIDATE As Long = &H100&
Private Const OFN_ALLOWMULTISELECT As Long = &H200&
Private Const OFN_EXTENSIONDIFFERENT As Long = &H400&
Private Const OFN_PATHMUSTEXIST As Long = &H800&
Private Const OFN_FILEMUSTEXIST As Long = &H1000&
Private Const OFN_CREATEPROMPT As Long = &H2000&
Private Const OFN_SHAREAWARE As Long = &H4000&
Private Const OFN_NOREADONLYRETURN As Long = &H8000&
Private Const OFN_NOTESTFILECREATE As Long = &H10000
Private Const OFN_NONETWORKBUTTON As Long = &H20000
Private Const OFN_NOLONGNAMES As Long = &H40000
Private Const OFN_EXPLORER As Long = &H80000
Private Const OFN_NODEREFERENCELINKS As Long = &H100000
Private Const OFN_LONGNAMES As Long = &H200000
Private Const OFN_ENABLEINCLUDENOTIFY As Long = &H400000
Private Const OFN_ENABLESIZING As Long = &H800000
Private Const CDERR_DIALOGFAILURE As Long = &HFFFF&
Private Const CDERR_STRUCTSIZE As Long = &H1&
Private Const CDERR_INITIALIZATION As Long = &H2&
Private Const CDERR_NOTEMPLATE As Long = &H3&
Private Const CDERR_NOHINSTANCE As Long = &H4&
Private Const CDERR_LOADSTRFAILURE As Long = &H5&
Private Const CDERR_FINDRESFAILURE As Long = &H6&
Private Const CDERR_LOADRESFAILURE As Long = &H7&
Private Const CDERR_LOCKRESFAILURE As Long = &H8&
Private Const CDERR_MEMALLOCFAILURE As Long = &H9&
Private Const CDERR_MEMLOCKFAILURE As Long = &HA&
Private Const CDERR_NOHOOK As Long = &HB&
Private Const CDERR_REGISTERMSGFAIL As Long = &HC&
Private Const FNERR_SUBCLASSFAILURE As Long = &H3001&
Private Const FNERR_INVALIDFILENAME As Long = &H3002&
Private Const FNERR_BUFFERTOOSMALL As Long = &H3003&
Private Declare Function apiCommDlgExtendedError Lib "comdlg32.dll" Alias _
"CommDlgExtendedError" () As Long
Private Declare Function apiGetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Function GetOpenFileName(Owner As Long, File As String, Filter As
String, _
Title As String, FilterIndex As Long) As String
Const strcProcedure = "GetOpenFileName"
Dim ofn As OPENFILENAME
Dim lngExtendedError As Long
With ofn
.Flags = OFN_HIDEREADONLY + OFN_NOCHANGEDIR + OFN_FILEMUSTEXIST
.hwndOwner = Owner
.lpstrCustomFilter = String$(40, vbNullChar)
.lpstrDefExt = "MDB"
.lpstrFile = File & String$(2048 - Len(File), vbNullChar)
.lpstrFileTitle = String$(2048, vbNullChar)
.lpstrFilter = Filter
.lpstrInitialDir = CurrentProject.Path
.lpstrTitle = Title
.lStructSize = Len(ofn)
.nFilterIndex = FilterIndex
.nMaxCustFilter = Len(.lpstrCustomFilter)
.nMaxFile = Len(.lpstrFile)
.nMaxFileTitle = Len(.lpstrFileTitle)
End With
If apiGetOpenFileName(ofn) = 0 Then
lngExtendedError = apiCommDlgExtendedError()
Select Case lngExtendedError
Case 0
Err.Raise mlngcUserCancelled, strcProcedure, mstrcUserCancelled
Case CDERR_DIALOGFAILURE
Err.Raise mlngcDialogFailure, strcProcedure, mstrcDialogFailure
Case CDERR_STRUCTSIZE
Err.Raise mlngcStructSize, strcProcedure, mstrcStructSize
Case CDERR_INITIALIZATION
Err.Raise mlngcInitialization, strcProcedure,
mstrcInitialization
Case CDERR_NOTEMPLATE
Err.Raise mlngcNoTemplate, strcProcedure, mstrcNoTemplate
Case CDERR_NOHINSTANCE
Err.Raise mlngcNoHInstance, strcProcedure, mstrcNoHInstance
Case CDERR_LOADSTRFAILURE
Err.Raise mlngcLoadStrFailure, strcProcedure,
mstrcLoadStrFailure
Case CDERR_FINDRESFAILURE
Err.Raise mlngcFindResFailure, strcProcedure,
mstrcFindResFailure
Case CDERR_LOADRESFAILURE
Err.Raise mlngcLoadResFailure, strcProcedure,
mstrcLoadResFailure
Case CDERR_LOCKRESFAILURE
Err.Raise mlngcLockResFailure, strcProcedure,
mstrcLockResFailure
Case CDERR_MEMALLOCFAILURE
Err.Raise mlngcMemAllocFailure, strcProcedure,
mstrcMemAllocFailure
Case CDERR_MEMLOCKFAILURE
Err.Raise mlngcMemLockFailure, strcProcedure,
mstrcMemLockFailure
Case CDERR_NOHOOK
Err.Raise mlngcNoHook, strcProcedure, mstrcNoHook
Case CDERR_REGISTERMSGFAIL
Err.Raise mlngcRegisterMsgFail, strcProcedure,
mstrcRegisterMsgFail
Case FNERR_SUBCLASSFAILURE
Err.Raise mlngcSubClassFailure, strcProcedure,
mstrcSubClassFailure
Case FNERR_INVALIDFILENAME
Err.Raise mlngcInvalidFileName, strcProcedure,
mstrcInvalidFileName
Case FNERR_BUFFERTOOSMALL
Err.Raise mlngcBufferTooSmall, strcProcedure,
mstrcBufferTooSmall
Case Else
Debug.Assert False
End Select
Else
GetOpenFileName = TrimNull(ofn.lpstrFile)
End If
End Function
Private Function TrimNull(ByRef strTrimThis As String, _
Optional ByRef boolTwoNulls As Boolean) As String
Dim lngPos As Long
Dim strFindThis As String
Dim strTemp As String
If boolTwoNulls Then
strFindThis = vbNullChar & vbNullChar
Else
strFindThis = vbNullChar
End If
lngPos = InStr(1, strTrimThis, strFindThis)
If lngPos > 0 Then
strTemp = Left$(strTrimThis, lngPos - 1)
Else
strTemp = strTrimThis
End If
If Len(strTemp) > 0 Then
If Right$(strTemp, 1) = vbNullChar Then
strTemp = Left$(strTemp, Len(strTemp) - 1)
End If
End If
TrimNull = strTemp
End Function