Jump to content

Problems with help file example


Peter86
 Share

Recommended Posts

Hi all,

I'm trying to add an icon picker to a script i'm working on, and I found an example in the helpfile for autoit, but it doesn't work properly. It seems that as as soon as file path with a space is chosen, it returns crap instead of the filename. The code I'm using is as follows:

CODE
; *******************************************************

; Example 3 - Show the Windows PickIconDlg

; *******************************************************

;; added here due to (34) : ==> Variable used without being declared.

$stBuffer = 0

$stFile = 0

$stIcon = 0

;; end addition

$sFileName = @SystemDir & '\shell32.dll'

; Create a strcuture to store the icon index

$stIcon = DllStructCreate("int")

If @OSType = "WIN32_NT" Then

; Convert and store the filename as a wide char string

$nBuffersize = DllCall("kernel32.dll", "int", "MultiByteToWideChar", "int", 0, "int", 0x00000001, "str", $sFileName, "int", -1, "ptr", 0, "int", 0)

$stString = DLLStructCreate("byte[" & 2 * $nBuffersize[0] & "]")

DllCall("kernel32.dll", "int", "MultiByteToWideChar", "int", 0, "int", 0x00000001, "str", $sFileName, "int", -1, "ptr", DllStructGetPtr($stString), "int", $nBuffersize[0])

Else

; Win'9x

$stString = DLLStructCreate("char[260]")

DllStructSetData($stString, 1, $sFileName)

EndIf

; Run the PickIconDlg - '62' is the ordinal value for this function

DllCall("shell32.dll", "none", 62, "hwnd", 0, "ptr", DllStructGetPtr($stString), "int", DllStructGetSize($stString), "ptr", DllStructGetPtr($stIcon))

If @OSType = "WIN32_NT" Then

; Convert the new selected filename back from a wide char string

$nBuffersize = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "int", 0, "int", 0x00000200, "ptr", DllStructGetPtr($stString), "int", -1, "ptr", 0, "int", 0, "ptr", 0, "ptr", 0)

$stFile = DLLStructCreate("char[" & $nBuffersize[0] & "]")

DllCall("kernel32.dll", "int", "WideCharToMultiByte", "int", 0, "int", 0x00000200, "ptr", DllStructGetPtr($stString), "int", -1, "ptr", DllStructGetPtr($stFile), "int", $nBuffersize[0], "ptr", 0, "ptr", 0)

$sFileName = DllStructGetData($stFile, 1)

Else

$sFileName = DllStructGetData($stString, 1)

EndIf

$nIconIndex = DllStructGetData($stIcon, 1)

; Show the new filename and icon index

Msgbox(0, "Info", "Last selected file: " & $sFileName & @LF & "Icon-Index: " & $nIconIndex)

$stBuffer = 0

$stFile = 0

$stIcon = 0

For example, when I choose "C:\Program Files\Daemon Tools\daemon.exe", "0" is returned as the filename, and I get a windows error reporting message saying that AppName: autoit3.exe (3.2.2.0), ModName: ntdll.dll (5.1.2600.2180) has encountered a problem.

Can anybody tell me whats going on? I'm running the latest stable version of AutoIt3 (v3.2.2.0).

regards,

pfeerick

OS: Windows XP SP2, AutoIt version: 3.2.12.0
Link to comment
Share on other sites

Well its made for icons inside Dll as far as i can see and the icon in daemon is not in a ini but in the exefile itself

Thanks, but don't think that's the problem... just tried 'C:\Program Files\Microsoft Office\Office12\OART.DLL', and that had the same error. The icon picker should work for dll, exe, cpl and ico files, but isn't when using the example code from the help file. The icon picker I'm referring to is the same one you see when you go into the properties for a shortcut, and click on the 'change icon' button.

Edit: Just tried the oart.dll again, but from C:\temp\oart.dll, and there wan't any problems, so for some reason file paths with spaces don't work properly! Any ideas why?

Edited by Peter86
OS: Windows XP SP2, AutoIt version: 3.2.12.0
Link to comment
Share on other sites

  • 2 weeks later...

Does anybody know how to resolve this problem - re: spaces in returned path result in AutoIt crashing, seemingly upon the 'Convert the new selected filename back from a wide char string' code.

Please remember, this is an example almost straight out of the help file (the 3rd example for the DllCall function)... I've only added the first nine lines - and the code in that section didn't make any difference to the main problem... it just fixed a warning I got when the 'AutoIt3 Syntax Checker' was run. I've attached the code so you can just download and run it.

Edited by Peter86
OS: Windows XP SP2, AutoIt version: 3.2.12.0
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...