Working shgetspecialfolderlocation example

Started by James Padgett, October 13, 2011, 10:34:35 PM

Previous topic - Next topic

James Padgett

Does anyone have a working example of  shgetspecialfolderlocation  ?

I get errors when I try to compile this:  ( even if I comment out the Function )


nifile = GetSpecialFolderLocation ( HWND_FORM1, %CSIDL_APPDATA )

Function GetSpecialFolderLocation (ByVal hwndOwner As Dword, ByVal nFolder As Long) As String

   Local pidl As Dword                     ' pointer to an item identifier list (PIDL)
   Local szPath As Asciiz * %MAX_PATH      ' folder's path
   
   If SHGetSpecialFolderLocation(hwndOwner, nFolder, pidl) = %S_OK Then
      SHGetPathFromIDList ByVal pidl, szPath
      CoTaskMemFree pidl
      Function = szPath
   End If

End Function


Error 466 in  ...\shlobj.inc: This name is already in use.
Line xxx  MACRO SHGetPathFromIDList= SHGetPathFromIDListA
A likely conflict is in ...\CODEGEN_xxx_main.bas
Line 71: Declare Function SHGetPathFromIDList Lib "SHELL32.D ...

José Roca

Remove the Declare Function SHGetPathFromIDList Lib "SHELL32.D ...

James Padgett

I guess this is a Firefly issue if I have to edit the CODEGEN_xxx_main.bas
file after the fact ??


José Roca

I don't know. You don't give any clues. It's a new application written with the last version? It's an existing one originally written with another version? Did you add the declare?, etc.

James Padgett

Just a FF3 app that worked without error when :

1 - PB 9 using PB includes

Broken  using Jose includes PB9 and PB10 .

I am no expert, but doesn't FF create the CODEGEN_xxx_main.bas ?


José Roca

#5
FF 3.5 can only be used with PB 10 and my includes for PB 10.

FF creates CODEGEN_xxx_main.bas, but this code:


nifile = GetSpecialFolderLocation ( HWND_FORM1, %CSIDL_APPDATA )

Function GetSpecialFolderLocation (ByVal hwndOwner As Dword, ByVal nFolder As Long) As String

   Local pidl As Dword                     ' pointer to an item identifier list (PIDL)
   Local szPath As Asciiz * %MAX_PATH      ' folder's path
   
   If SHGetSpecialFolderLocation(hwndOwner, nFolder, pidl) = %S_OK Then
      SHGetPathFromIDList ByVal pidl, szPath
      CoTaskMemFree pidl
      Function = szPath
   End If

End Function


and the conflicting declare must have been added by you.

You no longer have to add your own declares.

James Padgett

I am stummped..   I created a new project and the getspecialfolder funciton works fine..
For the original project..
I set project to delete files after compile.. made sure only source code was left , then set
project to 'not' delete files after compile..  just to make sure there wasn't something old left behind.

I have no idea where the errant declare could be .. it isn't in any of my obvious files..
I have searched for Declare in all of my project files and it doesn't find any.

Is there somewhere else I should look...?


The declares are definately in the Codegen_FSCCONF_MAIN.bas

DECLARE FUNCTION SHBrowseForFolder LIB "SHELL32.DLL" ALIAS "SHBrowseForFolderA" ( _
   BYREF lpbi AS BROWSEINFO _                          ' __in_out LPBROWSEINFO lpbi
) AS DWORD

DECLARE FUNCTION SHGetPathFromIDList LIB "SHELL32.DLL" ALIAS "SHGetPathFromIDListA" ( _
   BYVAL pidl AS DWORD _                                ' __in PCIDLIST_ABSOLUTE pidl
, BYREF pszPath AS ASCIIZ _                            ' __out LPSTR pszPath
) AS LONG                       


Here is my FF_AppStart:

#COMPILE Exe "//PROJECT_NAME//.exe"

' #BLOAT <num_expr>
' #COMPILER PBWIN
#Debug Error ON'|OFF
#DIM ALL'|NONE
' #OPTION {VERSION3 | VERSION4 | VERSION5}
' #REGISTER {ALL | DEFAULT | NONE}
' #TOOLS [ON|+ | OFF|-]
' #STACK <num_expr>

' FireFly will automatically replace the JOSEINCLUDES token based on the controls that are present
' in the project. If Jose Roca's includes are not specified in 'Environment Options' for the compiler
' then FireFly will simply use the default PowerBASIC Win32 API Include files that ship with the compiler.
//JOSEINCLUDES//
#If Not %DEF( %USE_JOSE_INCLUDES )
#INCLUDE "WIN32API.INC"
#INCLUDE "COMMCTRL.INC"  ' needed for WinXP Theme support
#INCLUDE "COMDLG32.INC"
#INCLUDE "RICHEDIT.INC"
#EndIf

' Place your user defined Declares, Constants, and #Include files below this line. FireFly will not
' parse any of your defined #Include files - it simply includes it in the final generated code.
' -------------------------------------------------------------------------------------------------
#INCLUDE "c:\winlift\winlift.inc"
'#INCLUDE "AFXSHELL.inc"
'#INCLUDE "windows.inc"
#INCLUDE "shlobj.inc"

Global gsFDATA() As String
Global gztrace As Long
Global gsstartpath As String
%OFN_FORCESHOWHIDDEN      = &H10000000



James Padgett

I am now wondering where in my project the errant Declare could be..

Any ideas where to search .. it is now a challenge to find this and not a real support issue..


José Roca

My only guess is:

#INCLUDE "c:\winlift\winlift.inc"

Paul Squires

I think that FF outputs those declares if Win2000 is selected as the operating system.... I'll have to check to be sure.
Paul Squires
PlanetSquires Software

Paul Squires

If the "win2kfix.inc" file exists in your FireFly installation folder, try renaming it or moving it out of that location. Maybe you installed FF3.5 into the same folder as FF3 ????? If you did, then you probably shouldn't have :)  I think that I warned of that in the download post.

Hopefully this is the answer to your problem.
Paul Squires
PlanetSquires Software

James Padgett

The win2k option was it... 

Dadburn keyboard virus ....

Thanks to all for their assistance....

Barry Gordon

Hi,

I came across this post when I was trying to find a solution to the problem that I had encountered when I moved from Windows XP to Windows7  and found that a program I had written was complaining that I had tried to put application data (i.e. configuration data) into the protected Program Files directory.    The solution apparently is to write this type of data into the My Documents equivalent.   So the problem is how to find out the real value of 'My Documents' so that it works on various versions of windows and is forward compatible if possible.

After an evening of searching the web I came across this post and discovered that the sample program that I had concocted was virtually identical to the one in this post (that cheered me up). Basically I thought - find the value of %CSIDL_PERSONAL - job done and it should then work on any version of Windows within reason.

However, I made the mistake of searching a bit too far and came across this link: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762494%28v=vs.85%29.aspx and its said that since Vista you should not use CSDIL values as they were obsolete.

So I am now completely confused.   I have a program that I want to run on Windows 7 and also on Windows XP and can't decide whether I should be using CSIDL_Personal  or FOLDERID_Documents  - and if the latter then where do I start to find the directory value.

So - advice would be greatly appreciated please on where I go from here.  Am I thinking too deeply and should just stop with the current CSDIL solutions or should I give myself and even bigger migraine.

Thanks
Barry

James Padgett

Jose's includes  to the rescue again ..

KnownFolders.inc

Barry Gordon

Hi James,

Thanks -I had already found this - but how do you actually use it.

Presumably you can't just plug any values into the GetSpecialFolderLocation/SHGetSpecialFolderLocation routine in Jose' example above as the latter is expecting a CSIDL value   (I tried and it just complains).   

I've spent another half day browsing the Internet and I'm getting more confused - e.g. if I actually did fathom out how to get KnownIDS to work - then will they actually work on (say) WIndows XP - or would it complain that it was missing  its frontal lobes.

Given that I have solution that meets current needs then I'm beginning to think that I will just stick with CSIDL and wait until my personal knowledge catches up.

Cheers
Barry