CommDlgExtendedError Function

Declare Function CommDlgExtendedError Lib "comdlg32.dll" () As Long

Platforms: Win 32s, Win 95/98, Win NT

CommDlgExtendedError returns the error code from the last common dialog box function. This function does not return error codes for any other API function; for that, use GetLastError instead. The function's return value is undefined if the last common dialog function call was successful. If an error with a common dialog function did occur, the return value is exactly one of the following common dialog error flags:

CDERR_DIALOGFAILURE = &HFFFF
The function could not open the dialog box.
CDERR_FINDRESFAILURE = &H6
The function failed to find the desired resource.
CDERR_GENERALCODES = &H0
The error involved a general common dialog box property.
CDERR_INITIALIZATION = &H2
The function failed during initialization (probably insufficient memory).
CDERR_LOADRESFAILURE = &H7
The function failed to load the desired resource.
CDERR_LOADSTRFAILURE = &H5
The function failed to load the desired string.
CDERR_LOCKRESFAILURE = &H8
The function failed to lock the desired resource.
CDERR_MEMALLOCFAILURE = &H9
The function failed to allocate sufficient memory.
CDERR_MEMLOCKFAILURE = &HA
The function failed to lock the desired memory.
CDERR_NOHINSTANCE = &H4
The function was not provided with a valid instance handle (if one was required).
CDERR_NOHOOK = &HB
The function was not provided with a valid hook function handle (if one was required).
CDERR_NOTEMPLATE = &H3
The function was not provided with a valid template (if one was required).
CDERR_REGISTERMSGFAIL = &HC
The function failed to successfully register a window message.
CDERR_STRUCTSIZE = &H1
The function was provided with an invalid structure size.
CFERR_CHOOSEFONTCODES = &H2000
The error involved the Choose Font common dialog box.
CFERR_MAXLESSTHANMIN = &H2002
The function was provided with a maximum font size value smaller than the provided minimum font size.
CFERR_NOFONTS = &H2001
The function could not find any existing fonts.
FNERR_BUFFERTOOSMALL = &H3003
The function was provided with a filename buffer which was too small.
FNERR_FILENAMECODES = &H3000
The error involved the Open File or Save File common dialog box.
FNERR_INVALIDFILENAME = &H3002
The function was provided with or received an invalid filename.
FNERR_SUBCLASSFAILURE = &H3001
The function had insufficient memory to subclass the list box.
FRERR_BUFFERLENGTHZERO = &H4001
The function was provided with an invalid buffer.
FRERR_FINDREPLACECODES = &H4000
The error involved the Find or Replace common dialog box.
PDERR_CREATEICFAILURE = &H100A
The function failed to create an information context.
PDERR_DEFAULTDIFFERENT = &H100C
The function was told that the information provided described the default printer, but the default printer's actual settings were different.
PDERR_DNDMMISMATCH = &H1009
The data in the two data structures describe different printers (i.e., they hold conflicting information).
PDERR_GETDEVMODEFAIL = &H1005
The printer driver failed to initialize the DEVMODE structure.
PDERR_INITFAILURE = &H1006
The function failed during initialization.
PDERR_LOADDRVFAILURE = &H1004
The function failed to load the desired device driver.
PDERR_NODEFAULTPRN = &H1008
The function could not find a default printer.
PDERR_NODEVICES = &H1007
The function could not find any printers.
PDERR_PARSEFAILURE = &H1002
The function failed to parse the printer-related strings in WIN.INI.
PDERR_PRINTERCODES = &H1000
The error involved the Print common dialog box.
PDERR_PRINTERNOTFOUND = &H100B
The function could not find information in WIN.INI about the requested printer.
PDERR_RETDEFFAILURE = &H1003
The handles to the data structures provided were nonzero even though the function was asked to return information about the default printer.
PDERR_SETUPFAILURE = &H1001
The function failed to load the desired resources.

Example:

' Give the Open File dialog box an insufficient buffer size.
' Then display the error code provided.
Dim filebox As OPENFILENAME  ' structure that sets the dialog box
Dim fname As String  ' will receive selected file's name
Dim retval As Long  ' return value
Dim errcode As long  ' receives the error code

' Configure how the dialog box will look
filebox.lStructSize = Len(filebox)  ' the size of the structure
filebox.hwndOwner = Form1.hWnd  ' handle of the form calling the function
filebox.lpstrTitle = "Open File"  ' text displayed in the box's title bar
' The next line sets up the file types drop-box
filebox.lpstrFilter = "Text Files" & vbNullChar & "*.txt" & vbNullChar & "All Files" & vbNullChar & "*.*" & vbNullChar & vbNullChar
filebox.lpstrFile = ""  ' ERROR: an empty buffer!
filebox.nMaxFile = 0  ' length of file and pathname buffer
filebox.lpstrFileTitle = Space(255)  ' initialize buffer that receives filename of file
filebox.nMaxFileTitle = 255  ' length of filename buffer
' Allow only existing files and hide the read-only check box
filebox.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY

' Execute the dialog box
retval = GetOpenFileName(filebox)
If retval = 0 Then  ' some error occured, or Cancel was pressed
  errcode = CommDlgExtendedError()  ' get the error code for GetOpenFileName
  If errcode = FNERR_BUFFERTOOSMALL Then
    Debug.Print "The buffer provided was too small to hold the filename."
  If errcode = FNERR_INVALIDFILENAME Then
    Debug.Print "An invalid filename was provided."
  ' etc.
  End If
End If

See Also: GetLastError
Category: Common Dialog

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/c/commdlgextendederror.html