Sign in to follow this  
Followers 0
lsakizada

Crash on exit application

15 posts in this topic

I have a crash when I closing compiled application by clicking on the [x] button.

but, when I closed the application that ran from sciTE editor its not crashed (also clicking on the [x] button).

what can be the cause?


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

For example not properly discarded resources (gdi objects, imagelists...).

Actually I just saw that if the following line commented then there is no crash at all

Local $Ret = DllCall($g_hShell32, 'dword_ptr', 'SHGetFileInfoW', 'wstr', $sPath, 'dword', $iAttributes, 'ptr', $p_tSHFILEINFO, 'uint', DllStructGetSize($tSHFILEINFO), 'uint', $iFlags)

the variable $g_hShell32 is defind on top of the file:

Global $g_hShell32 = DllOpen('shell32.dll')

but I do not want to comment it yehhh :)

the all function is:

Func __GetFileIcon($sPath, $bExt = 1, $iAttributes = 0)
    Static $tSHFILEINFO = DllStructCreate("ptr hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];"), $p_tSHFILEINFO = DllStructGetPtr($tSHFILEINFO)
    Local $iFlags = BitOR(0x100, 0x1) ;$SHGFI_SMALLICON, $SHGFI_ICON
    If $bExt Then $iFlags = BitOR($iFlags, 0x10);SHGFI_USEFILEATTRIBUTES
     
    Local $Ret = DllCall($g_hShell32, 'dword_ptr', 'SHGetFileInfoW', 'wstr', $sPath, 'dword', $iAttributes, 'ptr', $p_tSHFILEINFO, 'uint', DllStructGetSize($tSHFILEINFO), 'uint', $iFlags)
    If @error Then Return SetError(1, 0, 0)
    $Result = DllStructGetData($tSHFILEINFO, 'hIcon')
    
    Return $Result
EndFunc   ;==>__GetFileIcon
Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

SHGetFileInfo

http://msdn.microsoft.com/en-us/library/bb762179%28v=vs.85%29.aspx

"If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it."

So for each call to that function an icon handle is created which needs to be destroyed with a respective call of _WinAPI_DestroyIcon($hIcon).

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

SHGetFileInfo

http://msdn.microsoft.com/en-us/library/bb762179%28v=vs.85%29.aspx

"If SHGetFileInfo returns an icon handle in the hIcon member of the SHFILEINFO structure pointed to by psfi, you are responsible for freeing it with DestroyIcon when you no longer need it."

So for each call to that function an icon handle is created which needs to be destroyed with a respective call of _WinAPI_DestroyIcon($hIcon).

Hi Kafu,

I am calling this function three times on my application and all time i destroy the icon

Case StringUpper(".ico")                    $hIcon = __GetFileIcon($aResult[$i][5])
                    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
                    _GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)
                    _WinAPI_DestroyIcon($hIcon) ;
                Case StringUpper(".exe")
                    $hIcon = __GetFileIcon($aResult[$i][5])
                    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
                    _GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)
                    _WinAPI_DestroyIcon($hIcon) ;
                Case StringUpper(".lnk")
                    Local $aShortcut
                    $azShortInfo = FileGetShortcut($aResult[$i][5])
                    If IsArray($azShortInfo) Then $sFile = $azShortInfo[0]
                    $aShortcut = FileGetShortcut($aResult[$i][5])
                    ;$ext = _GetExtension($aShortcut[0])
                    $hIcon = __GetFileIcon($aShortcut[0])
                    ;$hIcon = _WinAPI_ShellExtractAssociatedIcon($ext, 1) ;
                    ;ConsoleWrite("$hIcon=" & $hIcon & @LF)
                    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
                    _GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)

                    _WinAPI_DestroyIcon($hIcon) ;
Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Do you release the $hImageList on exit?

You might be right. I do not closing it (I commented it by mistake)

But now when I try to use it its still crash.I close it at on exit function but still crashing.

see my all function

Func _SetLinks($Control, $Group)
    Local $sSQLText
    Local $aResult, $iRows, $iColumns, $iRval
    _AutoItObject_Startup()
    $sSQLText = _oSQLText()
    $sSQLText.TableName = "Links"
    $sSQLText.Delimiter = "|"
    $sSQLText.Column = "LinkName|IsActive|HK1|HK2|Description|URL"
    $sSQLText.Where = "GroupName=" & "'" & $Group & "'"
    $iRval = _SQLite_GetTable2d(-1, $sSQLText.SelectColumns, $aResult, $iRows, $iColumns)
    If $iRval = $SQLITE_OK Then
        ;_SQLite_Display2DResult($aResult)
        _GUICtrlListView_BeginUpdate($A_CONTROL_TAB_0[4])
        _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($A_CONTROL_TAB_0[4]))
        _ArrayDelete($aResult, 0)
        ;       _GUICtrlListView_AddArray($A_CONTROL_TAB_0[4], $aResult)
        ;_ArrayDisplay($aResult)

        $hImageList = _GUIImageList_Create(16, 16, 6) ;
        _GUICtrlListView_SetImageList($A_CONTROL_TAB_0[4], $hImageList, 1) ;
        Local $ext
        For $i = 0 To UBound($aResult) - 1
            $ext = _GetExtension($aResult[$i][5])

            Switch StringUpper($ext)
                Case StringUpper(".ico")
                    $hIcon = __GetFileIcon($aResult[$i][5])
                    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
                    _GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)
                    _WinAPI_DestroyIcon($hIcon) ;
                Case StringUpper(".exe")
                    $hIcon = __GetFileIcon($aResult[$i][5])
                    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
                    _GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)
                    _WinAPI_DestroyIcon($hIcon) ;
                Case StringUpper(".lnk")
                    Local $aShortcut
                    $azShortInfo = FileGetShortcut($aResult[$i][5])
                    If IsArray($azShortInfo) Then $sFile = $azShortInfo[0]
                    $aShortcut = FileGetShortcut($aResult[$i][5])
                    $hIcon = __GetFileIcon($aShortcut[0])
                    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
                    _GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)
                    _WinAPI_DestroyIcon($hIcon) ;

                Case Else
                    ;ConsoleWrite("3$ext[" & $aResult[$i][5] & "] = " & $ext & @LF)
                    $hIcon = _WinAPI_ShellExtractAssociatedIcon($ext, 1) ;
                    ;ConsoleWrite("$hIcon=" & $hIcon & @LF)
                    _GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
                    _GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
                    _GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)

                    _WinAPI_DestroyIcon($hIcon) ;

            EndSwitch

            ;$hIcon = _WinAPI_ShellExtractAssociatedIcon($ext, 1) ;
            ;ConsoleWrite("$hIcon=" & $hIcon & @LF)
            ;_GUIImageList_ReplaceIcon($hImageList, -1, $hIcon) ;
            ;_GUICtrlListView_AddItem($A_CONTROL_TAB_0[4], $aResult[$i][0], $i, _GUICtrlListView_GetItemCount($A_CONTROL_TAB_0[4]) + 9999) ;
            ;_GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][1], 1)
            ;_GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][2], 2)
            ;_GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][3], 3)
            ;_GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][4], 4)
            ;_GUICtrlListView_AddSubItem($A_CONTROL_TAB_0[4], $i, $aResult[$i][5], 5)

            ;_WinAPI_DestroyIcon($hIcon) ;

        Next


            _GUIImageList_Destroy($hImageList)


        For $x = 1 To _GUICtrlListView_GetColumnCount($A_CONTROL_TAB_0[4])

            _GUICtrlListView_SetColumnWidth($A_CONTROL_TAB_0[4], $x - 1, $LVSCW_AUTOSIZE_USEHEADER)
        Next

        _GUICtrlListView_EndUpdate($A_CONTROL_TAB_0[4])


        $sSQLText = 0
        $aResult = 0
        _AutoItObject_Shutdown()
    Else
        _Report_SQLLite_Error()
        $sSQLText = 0
        _AutoItObject_Shutdown()
        Return 0 ; error
    EndIf
EndFunc   ;==>_SetLinks
Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

Hmmm, can't see anything obvious in that function. You're running an x64 system? Then the structure in __GetFileIcon() might be faulty. Try compiling as x86. Otherwise if you want you can PM me the whole code, will be handled confidential and deleted after review :) ...

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hmmm, can't see anything obvious in that function. You're running an x64 system? Then the structure in __GetFileIcon() might be faulty. Try compiling as x86. Otherwise if you want you can PM me the whole code, will be handled confidential and deleted after review :) ...

I am runnning under x86. I planed to run it on all systems. Why its faulty?

EDIT: Yes you are right too: Its not running under x64 OS (windows 2008)

Edit 2: It is working on windows 2008 64. See post #13 on this thread!

The corrected function is on post # 11

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

I have a crash when I closing compiled application by clicking on the [x] button.

but, when I closed the application that ran from sciTE editor its not crashed (also clicking on the [x] button).

what can be the cause?

WCHAR not CHAR

you are using Unicode version of SHGetFileInfo


I see fascists...

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

WCHAR not CHAR

you are using Unicode version of SHGetFileInfo

Hi Rover, thank you very much. This solve the crash.

But Kafu put my attention to the fact that the function __GetFileIcon can not run on x64 machine.

I went to test it immediately, and you know what it did not work indeed.

Now I have bigger problem :) because my project stuck.

Have you any idea how to change the structure in __GetFileIcon() so it will work on x64 machines?

Or any other alternative to the function __GetFileIcon() ?

have a Best One.

EDIT: I am compiling it as x86

Func __GetFileIcon($sPath, $bExt = 1, $iAttributes = 0)
    Static $tSHFILEINFO = DllStructCreate("ptr hIcon; int iIcon; DWORD dwAttributes; WCHAR szDisplayName[255]; WCHAR szTypeName[80];"), $p_tSHFILEINFO = DllStructGetPtr($tSHFILEINFO)
    Local $iFlags = BitOR(0x100, 0x1) ;$SHGFI_SMALLICON, $SHGFI_ICON
    If $bExt Then $iFlags = BitOR($iFlags, 0x10);SHGFI_USEFILEATTRIBUTES
     
    Local $Ret = DllCall($g_hShell32, 'dword_ptr', 'SHGetFileInfoW', 'wstr', $sPath, 'dword', $iAttributes, 'ptr', $p_tSHFILEINFO, 'uint', DllStructGetSize($tSHFILEINFO), 'uint', $iFlags)
    If @error Then Return SetError(1, 0, 0)
    $Result = DllStructGetData($tSHFILEINFO, 'hIcon')
    
    Return $Result
EndFunc   ;==>__GetFileIcon
Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I'm not on an x64 OS, but to hazzard a guess, I would say use int_ptr instead of ptr.

Edit: typo

Func __GetFileIcon($sPath, $bExt = 1, $iAttributes = 0)
    Static $tSHFILEINFO = DllStructCreate("int_ptr hIcon; int iIcon; DWORD dwAttributes; WCHAR szDisplayName[255]; WCHAR szTypeName[80];"), $p_tSHFILEINFO = DllStructGetPtr($tSHFILEINFO)
    Local $iFlags = BitOR(0x100, 0x1) ;$SHGFI_SMALLICON, $SHGFI_ICON
    If $bExt Then $iFlags = BitOR($iFlags, 0x10);SHGFI_USEFILEATTRIBUTES

    Local $Ret = DllCall($g_hShell32, 'dword_ptr', 'SHGetFileInfoW', 'wstr', $sPath, 'dword', $iAttributes, 'int_ptr', $p_tSHFILEINFO, 'uint', DllStructGetSize($tSHFILEINFO), 'uint', $iFlags)
    If @error Then Return SetError(1, 0, 0)
    $Result = DllStructGetData($tSHFILEINFO, 'hIcon')

    Return $Result
EndFunc   ;==>__GetFileIcon
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hi Guys,

I want to apologize, the function __GetFileIcon after the correction of rover is working on windows 2008 x64.

It was a coding mistake of mine while I try to solve the crash with Kafu. ( some stupid typo crash it :) )

Many many thanks to Kafu and rover that help me to figure out this issue.

Also thanks to Yashied that shared the function and other goodies.

Best reagrds G.K.

Edited by lsakizada

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

I'm not on an x64 OS, but to hazzard a guess, I would say use int_ptr instead of ptr.

Edit: typo

Func __GetFileIcon($sPath, $bExt = 1, $iAttributes = 0)
    Static $tSHFILEINFO = DllStructCreate("int_ptr hIcon; int iIcon; DWORD dwAttributes; WCHAR szDisplayName[255]; WCHAR szTypeName[80];"), $p_tSHFILEINFO = DllStructGetPtr($tSHFILEINFO)
    Local $iFlags = BitOR(0x100, 0x1) ;$SHGFI_SMALLICON, $SHGFI_ICON
    If $bExt Then $iFlags = BitOR($iFlags, 0x10);SHGFI_USEFILEATTRIBUTES

    Local $Ret = DllCall($g_hShell32, 'dword_ptr', 'SHGetFileInfoW', 'wstr', $sPath, 'dword', $iAttributes, 'int_ptr', $p_tSHFILEINFO, 'uint', DllStructGetSize($tSHFILEINFO), 'uint', $iFlags)
    If @error Then Return SetError(1, 0, 0)
    $Result = DllStructGetData($tSHFILEINFO, 'hIcon')

    Return $Result
EndFunc   ;==>__GetFileIcon

That doesn't make much sense.

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0