Jump to content

How do I deliberately produce an error to test _WinAPI_CommDlgExtendedError() ? [solved]


Recommended Posts

I have a script that uses _WinAPI_GetOpenFileName to open a file dialog box. I have code to handle an error returned by _WinAPI_CommDlgExtendedError() but I can't debug that code because I can't figure out any way to deliberately produce an error that would involve this.

Here's my script, with everything stripped out except just enough to show you what I'm trying to do:

#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <StringConstants.au3>
#include <WinAPI.au3>
#include <WinAPIDlg.au3>
#include <WinAPIFiles.au3>
#include <WindowsConstants.au3>

Global $gsProgramTitle = "Playlist Creator v2"

  Open_Existing_File()

Exit

; ==================================================================================================

Func Open_Existing_File()

  ; Debug_Print("Func Open_Existing_File() called")

  Local $aFile, $iError, $sErrorString, $sFile, $fhTheFile         ; I have too many similar-sounding variable names!
  Local $iMode, $sLine, $aTemp, $sTemp

  ; open file dialog box
  $aFile = _WinAPI_GetOpenFileName("", _                                                ; title
                                   "Playlist Script (create_*.au3)|All Files (*.*)", _  ; filter strings
                                   @WorkingDir, _                                       ; initial directory
                                   "", _                                                ; default file name (and path?)
                                   "", _                                                ; default extension
                                   1, _                                                 ; initial filter
                                   BitOR($OFN_FILEMUSTEXIST, $OFN_PATHMUSTEXIST, $OFN_HIDEREADONLY))  ; flags

  $iError = @error
  $sErrorString = _WinAPI_CommDlgExtendedError()   ; how to debug??
  If $iError = 10 Then
    ; user pressed Cancel
    MsgBox(0, $gsProgramTitle, "User pressed Cancel")
    Return
  EndIf
  If $aFile[0] = 0 Then
    ; no files returned - error must have occured
    ; Debug_Print("@error = " & $iError & " - _WinAPI_CommDlgExtendedError() returned: " & $sErrorString)
    MsgBox($MB_ICONERROR, $gsProgramTitle, "Error: " & $sErrorString)
    Return
  EndIf

  If $aFile[0] <> 2 Then
    MsgBox($MB_ICONERROR, $gsProgramTitle, "An unexpected error occurred.")
    Return
  EndIf

  if StringRight($aFile[1], 1) = "\" Then
    $sFile = $aFile[1] & $aFile[2]
  Else
    $sFile = $aFile[1] & "\" & $aFile[2]
  EndIf

  MsgBox(0, $gsProgramTitle, "File selected: " & $sFile)

EndFunc   ; Open_Existing_File

The line I need help with is of course the one labelled "; how to debug??"

I'm Using AutoIt version 3.3.14.2 on Windows 7.

Any help would be appreciated. Thank you.

Link to post
Share on other sites
  • Ravenswood changed the title to How do I deliberately produce an error to test _WinAPI_CommDlgExtendedError() ? [solved]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...