GaryFrost Posted April 14, 2005 Share Posted April 14, 2005 (edited) Trying to figure out this dll call, haven't had any luck making it work correctly it returns an empty string. Any help would be appreciated. For example code Dim $s_path = _GetFilePath("c:\temp","google.gif") if @error Then MsgBox(0,"","file not found") Else MsgBox(0,"",$s_path) EndIf Func _GetFilePath($s_root,$s_file) Dim $s_path,$ret $ret = DllCall("imagehlp","long","SearchTreeForFile","str",$s_root,"str",$s_file,"str",$s_path) if $ret <> 0 Then Return $s_path EndIf SetError(1) return 0 EndFunc Edited April 14, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted April 14, 2005 Author Share Posted April 14, 2005 (edited) Any Ideas?can get pretty good apiviewer fromApiViewer is a replacement for Microsoft's API Viewer. The data-file is based on the latest WindowsXP header files, so that means you get access to approximately 6500 functions and 55600 constants! Win32api.txt has approximately 1500 functions and 5000 constants.This list contains 940 API-functions, all explained and illustrated with one or more examples. If you want to learn more about API, or don't know what API is, read thisText-file about the Win32 API-function calls (+/- 75 Kb). Edited April 14, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Lazycat Posted April 14, 2005 Share Posted April 14, 2005 Try this one: Func _GetFilePath($s_root,$s_file) Dim $s_path,$ret $ret = DllCall("imagehlp","long","SearchTreeForFile","str",$s_root,"str",$s_file,"str", $s_path) if IsArray($ret) Then Return $ret[3] EndIf SetError(1) return 0 EndFunc Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
GaryFrost Posted April 14, 2005 Author Share Posted April 14, 2005 Thanks, now that I know how that one works, gives me something to work with. SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted April 14, 2005 Author Share Posted April 14, 2005 (edited) if IsArray is not correct tho, always returns an array ; $ret[0] = return code (0 if failed, non zero if successfully found) ; $ret[1] = root path ; $ret[2] = file to search for ; $ret[3] = path with file name if successful, if not then empty string Func _GetFilePath($s_root,$s_file) Dim $s_path,$ret $ret = DllCall("imagehlp","long","SearchTreeForFile","str",$s_root,"str",$s_file,"str", $s_path) If($ret[0] <> 0) Then Return $ret[3] Else SetError(1) return 0 EndIf EndFunc this will work also, being that $s_path is never modified $ret = DllCall("imagehlp","long","SearchTreeForFile","str",$s_root,"str",$s_file,"str", "") Edited April 14, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
GaryFrost Posted April 14, 2005 Author Share Posted April 14, 2005 Dim $s_path = _GetFilePath("c:\temp","google.gif") if Not IsArray($s_path) Then MsgBox(0,"","file not found") Else for $i=1 to $s_path[0] MsgBox(0,"",$s_path[$i]) Next EndIf ; wild cards don't work with this call ; $ret[0] = return code (0 if failed, non zero if successfully found occurrence) ; $ret[1] = root path ; $ret[2] = file to search for ; $ret[3] = path with file name if successful, if not then empty string Func _GetFilePath($s_root,$s_file) Dim $ret $ret = DllCall("imagehlp","long","SearchTreeForFile","str",$s_root,"str",$s_file,"str", "") If($ret[0] <> 0) Then dim $ret_info[4] $ret_info[0] = 3 $ret_info[1] = $ret[3]; path with file name $ret_info[2] = StringMid($ret[3],1,StringInStr($ret[3],$s_file)-2); just the path no trailing backslash $ret_info[3] = $s_file; file name Return $ret_info Else return 0 EndIf EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Lazycat Posted April 14, 2005 Share Posted April 14, 2005 if IsArray is not correct tho, always returns an array You right, if call was successfull it will always return array. But if (theoretically) call will fail, non-array will be returned and $ret[0] will cause error. So maybe a bit safer to add @error check as well. Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Link to comment Share on other sites More sharing options...
GaryFrost Posted April 14, 2005 Author Share Posted April 14, 2005 got it, if for some reason the dllcall fails as i read it then it will set error to 1 array is not returned Dim $s_path = _GetFilePath("c:/","google.gif") if Not IsArray($s_path) Then MsgBox(0,"","file not found") Else for $i=1 to $s_path[0] MsgBox(0,"",$s_path[$i]) Next EndIf ; wild cards don't work with this call ; $ret[0] = return code (0 if failed, non zero if successfully found) ; $ret[1] = root path ; $ret[2] = file to search for ; $ret[3] = path with file name if successful, if not then empty string Func _GetFilePath($s_root,$s_file) Dim $ret,$s_troot = $s_root $s_troot = StringReplace($s_troot,"/","\") $ret = DllCall("imagehlp","long","SearchTreeForFile","str",$s_troot,"str",$s_file,"str", "") If(IsArray($ret)) Then If($ret[0] <> 0) Then dim $ret_info[4] $ret_info[0] = 3 $ret_info[1] = $ret[3]; path with file name $ret_info[2] = StringMid($ret[3],1,StringInStr($ret[3],$s_file)-2); just the path no trailing backslash $ret_info[3] = $s_file; file name Return $ret_info Else return 0 EndIf Else Return 0 EndIf EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
bshoenhair Posted April 14, 2005 Share Posted April 14, 2005 @gafrost Nice, I like it. 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