Jump to content

DllCall


Recommended Posts

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 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

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
Link to comment
Share on other sites

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 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

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

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.
Link to comment
Share on other sites

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

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...