Ravenswood Posted January 14, 2022 Share Posted January 14, 2022 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: expandcollapse popup#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 comment Share on other sites More sharing options...
markyrocks Posted January 14, 2022 Share Posted January 14, 2022 (edited) Press cancel on the window, if that doesn't work then press the x to close the window. All else fails use winkill. Oops hold on Edited January 14, 2022 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
Ravenswood Posted January 18, 2022 Author Share Posted January 18, 2022 I figured it out. By opening WinAPI.au3 I was able to see the source code of the _WinAPI_GetOpenFileName function. All I need to do is create my own fake version of that and have it deliberately error out. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now