Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Oct 24, 2017 1:03 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Mon Apr 22, 2013 11:35 am 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
I am making a little progress on this program.
I removed the Private statement on the two following lines to fix a syntax error.

Const MAX_PATH = 260
Declare Function SHGetFileInfo Lib "Shell32" Alias "SHGetFileInfoA" _

Now I am getting the following error that I hope someone can help me with.

Code, Window1.TextArea1.Open, line 18,
External functions cannot use objects as parameters,
(ByVal pszPath As Variant, ByVal dwFileAttributes As Integer, psfi As SHFILEINFO, _

pszPath is highlighted in this error message.


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Mon Apr 22, 2013 11:50 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
The Variant class is an object, which you can't pass to an external function. Change it to a CString in the declare.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Mon Apr 22, 2013 10:58 pm 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
I changed the line to:

(ByVal pszPath As CString, ByVal dwFileAttributes As Integer, psfi As SHFILEINFO, _

and that seems to be fine.

Now I am trying to follow the instruction from Matthew to call the path string from GetfolderItem("c:\myimage.png").absolutepath (example).
and I coded it as

dim f as folderitem
f = GetfolderItem(bgfile).absolutePath

but get the following error message

Code, Window1.TextArea1.Open, line 25,
Type mismatch error. Expected FolderItem, but got String, f = GetfolderItem(bgfile).absolutePath

I am lost on this. My thinking is that I use the GetfolderItem to open the file and then execute the function to obtain the file property comments.

following is the complete code as it is now:

dim bgfile as string
dim bgtext as string
Dim reg As New RegistryItem("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General", False)
bgfile = reg.Value("WallpaperSource")
bgtext = right(bgfile,len(bgfile)-51)
bgtext = left(bgtext,len(bgtext)-4)
TextArea1.Text = bgtext

Const MAX_PATH = 260

Declare Function SHGetFileInfo Lib "Shell32" Alias "SHGetFileInfoA" _
(ByVal pszPath As CString, ByVal dwFileAttributes As Integer, psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer

' Returns the description of the specified file/folder
' (for example "Folder", "Executable file", "Bmp Image" and so on)

dim f as folderitem
f = GetfolderItem(bgfile).absolutePath

Function GetFileDescription(ByVal sPath As String) As String
Const SHGFI_TYPENAME = &H400

Dim FInfo As SHFILEINFO

' retrieve the item's attributes
SHGetFileInfo sPath, 0, FInfo, Len(FInfo), SHGFI_TYPENAME
' read the szTypeName field
Return Left(FInfo.szTypeName, InStr(FInfo.szTypeName & _
chr(0), chr(0) - 1


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Tue Apr 23, 2013 1:15 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
dim f as folderitem
f = GetfolderItem(bgfile).absolutePath


f in the above snippet is a FolderItem, however the AbsolutePath property of the FolderItem (which is returned by GetFolderItem) is a String. Remove the .AbsolutePath part to assign the output of GetFolderItem to f, and then use f.AbsolutePath wherever you need to insert the path to the file, e.g.:

dim f as folderitem
f = GetfolderItem(bgfile) 'f now contains the folderitem returned from GetFolderItem
TextArea1.Text = f.AbsolutePath 'TextArea1 now contains the string representing the folderitem's path

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Tue Apr 23, 2013 1:51 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Isn't bgfile already the absolute path? Why do you need the folderitem?


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Tue Apr 23, 2013 1:33 pm 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
You are correct timhare, bgfile is the path. What I am trying to get now is the comments for bgfile from the file properties. This shows up on the details tab.


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Sun Apr 28, 2013 4:02 pm 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
I have tried to convert and make this code work but with my very limited program knowledge I have not been able to get it done.
Could someone please help me better understand how to convert and make this function do what I need to do?

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Wed May 01, 2013 9:59 pm 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
Below is the code that I am trying to run but getting a syntax error on the function line. I am running all the code from a textarea control open. Is this the correct way to do it or do I need
to put functions into a module?

dim bgfile as string
dim bgtext as string
Dim reg As New RegistryItem("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General", False)
bgfile = reg.Value("WallpaperSource")
bgtext = right(bgfile,len(bgfile)-51)
bgtext = left(bgtext,len(bgtext)-4)
TextArea1.Text = bgtext[/code]

Const MAX_PATH = 260[/code]

Declare Function SHGetFileInfo Lib "Shell32" Alias "SHGetFileInfoA" _
(ByVal pszPath As CString, ByVal dwFileAttributes As Integer, psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer

' Returns the description of the specified file/folder
' (for example "Folder", "Executable file", "Bmp Image" and so on)

dim f as folderitem
f = GetfolderItem(bgfile)
Function GetFileDescription(ByVal sPath As String) As String[/b][/b] (syntax error on this line)
Const SHGFI_TYPENAME = &H400

Dim FInfo As SHFILEINFO

' retrieve the item's attributes
SHGetFileInfo sPath, 0, FInfo, Len(FInfo), SHGFI_TYPENAME
' read the szTypeName field
Return Left(FInfo.szTypeName, InStr(FInfo.szTypeName & _
chr(0), chr(0) - 1


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Wed May 01, 2013 10:41 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Use Add Method to add it to the window, or add it to a Module. Either way. You cannot create a function in code. It must be with Add Method in the IDE.


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Thu May 02, 2013 11:46 am 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
Thanks timhare. One more problem solved. Now I just need to figure out what the syntax error is.
Also in the original code given to me my Matthew he says to call the path string from GetfolderItem("c:\myimage.png").absolutepath (example)
I am confused on this, can you explain just how to do it?


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Thu May 02, 2013 12:44 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
The syntax error is because you have a function statement (not "declare function", but "function") in the middle of your code. Move that to a Method definition instead.

Quote:
Also in the original code given to me my Matthew he says to call the path string from GetfolderItem("c:\myimage.png").absolutepath (example)
I am confused on this, can you explain just how to do it?

I believe what he is saying is: Get a folderitem that points to the file. You can do this in many different ways, but here is a simplistic example. You could also use SpecialFolder.Documents or any other means. That will enable you to extract the absolute path to the file, so you don't have to hard code it.

If you have a hard-coded path, and are ok with using that, then just use it directly and skip the folderitem business. It is merely a convenience to allow you to traverse the filesystem without having to hard code the path.


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Thu May 02, 2013 5:37 pm 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
Thanks for you very fast response. Here is a new listing of how I have changed my program.
I still am getting a syntax error on the function statement in module 2.
the code in the textarea open gives me the absolute path to the file so now I need the function to give me the comments from the file property details (from the meta data I guess) so that I can add those comments to the textarea window. I still am not understanding how to call the function in order to accomplish this.


This is the code in a textarea open:
'get the path for the current desktop background
dim bgfile as string
dim bgtext as string
Dim reg As New RegistryItem("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General", False)
bgfile = reg.Value("WallpaperSource")
bgtext = right(bgfile,len(bgfile)-51)
bgtext = left(bgtext,len(bgtext)-4)
'put the file name less extention in the textarea
TextArea1.Text = bgtext

Const MAX_PATH = 260

Declare Function SHGetFileInfo Lib "Shell32" Alias "SHGetFileInfoA" _
(ByVal pszPath As CString, ByVal dwFileAttributes As Integer, psfi As SHFILEData, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer

Here is the code in module 2: I am still getting a syntax error on the Function statement.
Function GetFileDescription(ByVal sPath As String) 'As String
Const SHGFI_TYPENAME = &H400

' Returns the description of the specified file/folder
' (for example "Folder", "Executable file", "Bmp Image" and so on)

Dim FInfo As SHFILEData

' retrieve the item's attributes
SHGetFileInfo sPath, 0, FInfo, Len(FInfo), SHGFI_TYPENAME
' read the szTypeName field
Return Left(FInfo.szTypeName, InStr(FInfo.szTypeName & chr(0), chr(0) - 1

Here is the data structure:
Structure SHFILEData
Declaration Offset Size
ilcon As Integer 0 4
dwAttributes As Integer 4 4
szDisplayName As String * 260 8 260
szTypeName As String * 80 268 80
hlcon As Integer 348 4
352


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Thu May 02, 2013 6:44 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Quote:
Function GetFileDescription(ByVal sPath As String) 'As String

This does not go in your code. This information is broken up and put into the method's Name, Parameters and Return Value fields.


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Fri May 03, 2013 1:04 pm 
Offline

Joined: Sun Dec 02, 2012 10:50 pm
Posts: 30
Thanks I think I am close to done now but here is the latest error that I can't figure out.

Code, Module2.GetFileDescription, line 13, You must use the value returned by this function, SHGetFileInfo sPath, 0, FInfo, Len("FInfo"), SHGFI_TYPENAME

here is the code that I now have in the module2:
Const SHGFI_TYPENAME = &H400

' Returns the description of the specified file/folder
' (for example "Folder", "Executable file", "Bmp Image" and so on)

Dim FInfo As SHFILEData

Declare Function SHGetFileInfo Lib "Shell32" Alias "SHGetFileInfoA" _
(ByVal pszPath As CString, ByVal dwFileAttributes As Integer, psfi As SHFILEData, _
ByVal cbFileInfo As Integer, ByVal uFlags As Integer) As Integer

' retrieve the item's attributes
SHGetFileInfo sPath, 0, FInfo, Len("FInfo"), SHGFI_TYPENAME
' read the szTypeName field
Return Left(FInfo.szTypeName, InStr(FInfo.szTypeName & chr(0), chr(0) - 1

Here is the code that I now have in the textarea open code:
'get the path for the current desktop background
dim bgfile as string
dim bgtext as string
dim bgcomments as string
Dim reg As New RegistryItem("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General", False)
bgfile = reg.Value("WallpaperSource")
bgtext = right(bgfile,len(bgfile)-51)
bgtext = left(bgtext,len(bgtext)-4)
'put the file name less extention in the textarea
TextArea1.Text = bgtext

Const MAX_PATH = 260

bgcomments = GetFileDescription(bgfile)
TextArea1.AppendText(bgcomments)


Top
 Profile  
Reply with quote  
 Post subject: Re: how do you access comments of a file from windows explor
PostPosted: Fri May 03, 2013 2:24 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Your declare returns an integer. You must do something with that. There are 3 possibilities, 2 will work.

dim n as integer

SHGetFileInfo ... // error, because you are not dealing with the return value
n = SHGetFileInfo ... // good, you have received the return value
call SHGetFileInfo ... // good, you are explicitly ignoring the return value


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 42 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 5 hours


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group