It is currently Wed Apr 01, 2020 7:42 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Win API call not working? [SOLVED]
PostPosted: Tue Jul 30, 2019 1:09 pm 
Offline
User
User

Joined: Fri Aug 31, 2018 9:23 am
Posts: 42
Location: Australia
Can anyone suggest why the following call always returns false?
Code:
EnableExplicit
Define Buffer$ = Space(256)
Define Result

Result = SearchTreeForFile_("D:\Temp\", "Dummy.txt", @Buffer$)
If Result=0
  MessageRequester("", "No file with this name was found.", 0)
Else
  MessageRequester("", "First found file: " + Buffer$, 0)
EndIf
PB5.71b2 on Win 7 x64 The referenced file definitely exists.


Last edited by davebar on Tue Jul 30, 2019 2:57 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 1:24 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1110
Location: Gernsbach (Germany)
This WinAPI function only works in ANSI mode.

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 1:44 pm 
Offline
User
User

Joined: Fri Aug 31, 2018 9:23 am
Posts: 42
Location: Australia
RSBasic wrote:
This WinAPI function only works in ANSI mode.
Can you please tell me how to set the ANSI mode?


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 1:49 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1110
Location: Gernsbach (Germany)
This is not possible in the newer PB version. You need the Unicode function of SearchTreeForFile_(). I don't know if a Unicode function exists.

Why don't you use the native function of PureBasic? (ExamineDirectory())

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 2:14 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Apr 26, 2003 2:49 pm
Posts: 662
You can call the unicode version, (i changed the file name):
Code:
EnableExplicit
Define Buffer$ = Space(256)
Define Result
Define.i hlib

Prototype p_SearchTreeForFileW(rt.s, ip.s, ob.i)
Global.p_SearchTreeForFileW SearchTreeForFileW

hlib = OpenLibrary(#PB_Any, "Dbghelp.dll")
SearchTreeForFileW = GetFunction(hlib, "SearchTreeForFileW")

Result = SearchTreeForFileW("c:\", "test.bin", @Buffer$)
If Result=0
  MessageRequester("", "No file with this name was found.", 0)
Else
  MessageRequester("", "First found file: " + Buffer$, 0)
EndIf

CloseLibrary(hlib)


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 2:22 pm 
Offline
User
User

Joined: Fri Aug 31, 2018 9:23 am
Posts: 42
Location: Australia
The native function ExamineDirectory() would have been my first choice, but I wanted to check out if your Win API example [1] might have been a better option
[1] https://www.rsbasic.de/aktualisierung/w ... 0suchen.pb
Many thanks for taking the time to help.


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 2:28 pm 
Offline
User
User

Joined: Fri Aug 31, 2018 9:23 am
Posts: 42
Location: Australia
Thanks Justin, that works very nicely.


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 2:36 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 638
Another solution:
Code:
EnableExplicit

Import "imagehlp.lib"
  SearchTreeForFile(Path.p-Ascii,File.p-ascii,*Result)
EndImport

Global *buffer

*buffer = AllocateMemory(#MAX_PATH)

If *buffer
  If SearchTreeForFile("D:\Temp\","Dummy.txt",*buffer)
    MessageRequester("", "First found file: " + PeekS(*buffer,-1,#PB_Ascii), 0)
  Else   
    MessageRequester("", "No file with this name was found.", 0)
  EndIf
  FreeMemory(*buffer)
EndIf

End


Or grab the proper lib from MSVS and import the W version directly.


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 2:42 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jun 22, 2003 7:43 pm
Posts: 488
Location: Germany, Saarbrücken
I am just curious. But is there also a WinAPI function which makes use of the indexed files for a faster search experience?

_________________
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.


Top
 Profile  
Reply with quote  
 Post subject: Re: Win API call not working?
PostPosted: Tue Jul 30, 2019 2:47 pm 
Offline
User
User

Joined: Fri Aug 31, 2018 9:23 am
Posts: 42
Location: Australia
Thanks Mijikai,
I never cease to be amazed by the skill and depth of knowledge in this forum.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Columbo, netmaestro and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye