Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ControlGet, result, List on desktop causing explorer crash


  • Please log in to reply
25 replies to this topic
fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
I have reports that this line causes explorer crashes, when desktop window is active:
ControlGet, result, List, Selected Col1, SysListView321, A

System on the 2 reports I received was both Windows 7 64bit.

I'm running ahk_l ansi version.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Have you tried using AutoHotkey64?

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
No, not yet. I have not experienced this myself, but I will see if this helps.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I wondered why AHK Window Info causes Explorer to crash...

AutoHotkey allocates inter-process memory for the ListView messages to return their data in, but aborts if the allocation failed. Since Explorer is crashing, I presume the allocation is "succeeding" but the 32-bit pointer value we're getting (and passing to Explorer) isn't really valid. I'll have to do some debugging.

The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= WM_USER) to another process, you must do custom marshalling.
Source: SendMessageTimeout Function

For an x86 process interacting with an x64 process, [VirtualAllocEx and related] functions work fine, though they can only see the low 4GB of the 64-bit address space (as for an x86 process, their arguments and return values are 32 bits wide).
Source: DLL Injection and WoW64 | Corsix.org

That's only relevant if AutoHotkey64 doesn't have the same issue.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009
I'm having the same issue. I'm using Autohotkey_L R60 Unicode on Windows 7 64bit.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Use the 64-bit build.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009
OK, I've just installed the 64-bit build with the installer and now it works. Thank you. So, if I want to compile scripts for 32bit systems, I need to use ladiko's Compile_AHK.exe and select AutoHotkeySC.bin for x86. I'm I correct?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Yes. Alternatively, use the /bin "binfile" command-line switch of Ahk2Exe_L, which is installed with AutoHotkey_L.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

Yes. Alternatively, use the /bin "binfile" command-line switch of Ahk2Exe_L, which is installed with AutoHotkey_L.

Thank you for the additional information.

By the way I have just realized that scripts using this line have to be compiled for the both 32-bit and 64-bit systems for distribution purposes, don't they? It means users who use 64-bit systems do not have a choice but to use the 64-bit compiled version.

I'm saying this just because I'm looking for the cleanest way to retrieve currently selecting file paths. I'd like to avoid messing up with Clipboard and I do not have the enough skill level to deal with COM.

How hard would it be to fix it? If it is not easy, I'll try to learn COM. But I guess other non-skilled coders would have to face hard time doing this too.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009

Yes. Alternatively, use the /bin "binfile" command-line switch of Ahk2Exe_L, which is installed with AutoHotkey_L.

Thank you for the additional information.

By the way I have just realized that scripts using this line have to be compiled for the both 32-bit and 64-bit systems for distribution purposes, don't they? It means users who use 64-bit systems do not have a choice but to use the 64-bit compiled version.

I'm saying this just because I'm looking for the cleanest way to retrieve currently selecting file paths. I'd like to avoid messing up with Clipboard and I do not have the enough skill level to deal with COM.

How hard would it be to fix it? If it is not easy, I'll try to learn COM. But I guess other non-skilled coders would have to face hard time doing this too.


Something like this, uses COM.ahk though:
ShellFolder(hWnd=0,returntype=0) 
{ 
	If   hWnd||(hWnd:=WinActive("ahk_class CabinetWClass"))||(hWnd:=WinActive("ahk_class ExploreWClass")) 
	{
		sa := Com_CreateObject("Shell.Application")
		
		;Find hwnd window
		wins := sa.Windows
		loop % wins.count
		{
			window:=wins.Item(A_Index-1)
			If Not InStr( window.FullName, "steam.exe" ) ; ensure pwb isn't Steam IE window which causes problems
				if(window.Hwnd=hWnd)
					break
		}
		doc:=window.Document
		sFolder   := doc.Folder.Self.path
		sDisplay := doc.Folder.Self.name
		;Don't get focussed item and selected files unless requested, because it will cause a COM error when called during/shortly after explorer path change sometimes
		if (returntype=2)
		{
			sFocus :=doc.FocusedItem.Path
			SplitPath, sFocus , sFocus
		}
		if(returntype=3 || returntype=4)
		{
			loop % doc.SelectedItems.Count
			{
				path :=doc.selectedItems.item(A_Index-1).Path "`n" ;= (returntype=3 ? sFolder "" COM_Invoke(doc.SelectedItems, "Item", A_Index-1).Name "`n" : COM_Invoke(doc.SelectedItems, "Item", A_Index-1).Name "`n")
				if(returntype=4)
					SplitPath, path , path
				sSelect.=path
			}
			StringReplace, sSelect, sSelect, \\ , \, 1 
		}
		;Remove last `n
		StringTrimRight, sSelect, sSelect, 1
		if (returntype=1)
			Return   sFolder
		else if (returntype=2)
			Return   sFocus
		else if (returntype=3)
			Return   sSelect
		else if (returntype=4)
			Return 	 sSelect
		else if (returntype=5)
			Return sDisplay
	}
}

It's not very clean but works fine for me, feel free to improve it.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

How hard would it be to fix it?

I won't know until I (try to) fix it.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

Something like this, uses COM.ahk though:

hmm, it doesn't work on my computer. It is supposed to return selected file paths, doesn't it? The code below just gives empty message boxes. (COM.ahk is installed)

^1::
	hwnd := WinExist("A") 
	if hwnd
	{
		;tooltip %hwnd%
		msgbox % ShellFolder(hwnd)
	}
Return

ShellFolder(hWnd=0,returntype=0)
{
   If   hWnd||(hWnd:=WinActive("ahk_class CabinetWClass"))||(hWnd:=WinActive("ahk_class ExploreWClass"))
   {
      sa := Com_CreateObject("Shell.Application")
      
      ;Find hwnd window
      wins := sa.Windows
      loop % wins.count
      {
         window:=wins.Item(A_Index-1)
         If Not InStr( window.FullName, "steam.exe" ) ; ensure pwb isn't Steam IE window which causes problems
            if(window.Hwnd=hWnd)
               break
      }
      doc:=window.Document
      sFolder   := doc.Folder.Self.path
      sDisplay := doc.Folder.Self.name
      ;Don't get focussed item and selected files unless requested, because it will cause a COM error when called during/shortly after explorer path change sometimes
      if (returntype=2)
      {
         sFocus :=doc.FocusedItem.Path
         SplitPath, sFocus , sFocus
      }
      if(returntype=3 || returntype=4)
      {
         loop % doc.SelectedItems.Count
         {
            path :=doc.selectedItems.item(A_Index-1).Path "`n" ;= (returntype=3 ? sFolder "" COM_Invoke(doc.SelectedItems, "Item", A_Index-1).Name "`n" : COM_Invoke(doc.SelectedItems, "Item", A_Index-1).Name "`n")
            if(returntype=4)
               SplitPath, path , path
            sSelect.=path
         }
         StringReplace, sSelect, sSelect, \\ , \, 1
      }
      ;Remove last `n
      StringTrimRight, sSelect, sSelect, 1
      if (returntype=1)
         Return   sFolder
      else if (returntype=2)
         Return   sFocus
      else if (returntype=3)
         Return   sSelect
      else if (returntype=4)
         Return     sSelect
      else if (returntype=5)
         Return sDisplay
   }
}

feel free to improve it

Thanks I'll try.

I won't know until I (try to) fix it.

Ok, thanks.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
Oh sorry, I just noticed that the default parameter for returntype is wrong. Valid values are 1,2,3 and 4. By reading the code you should see what they return, or just try it.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

Oh sorry, I just noticed that the default parameter for returntype is wrong. Valid values are 1,2,3 and 4. By reading the code you should see what they return, or just try it.


hmmm, sorry that I'm not still able to manipulate COM for now (planning to learn). I tried this but it just gives empty message boxes.

^1::
	hwnd := WinExist("A") 
	if hwnd
	{
		;tooltip %hwnd%
		Loop 6
			msgbox % ShellFolder(hwnd, A_Index-1) 
	}
Return


fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
I suppose that an explorer window was active when you called this?