Announcement

Collapse
No announcement yet.

Cleaning up path given by SHGetFolderPath

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cleaning up path given by SHGetFolderPath

    Code on the forum for determining the Application Data Folder with no backslash at the end
    Code:
    Local path As Asciiz*%MAX_PATH, etc.
    result = SHGetFolderPath(0, %CSIDL_COMMON_APPDATA, 0, 0, path)
    always seems to conclude by cleaning up path with either
    Code:
    ourpath = RTrim$(path, $Nul)
    or
    Code:
    n = Instr(-1,path, ANY "\:" )
    ourpath = Left$(path, n-1)
    or both. But if right after the call to SHGetFolderPath you put
    Code:
    msgbox "X"+path+"X",  "",  %MB_OK+%MB_SYSTEMMODAL
    you see a clean path already, no cleaning up is necessary. Is that correct?
    Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

  • #2
    You are correct. PB understanrds Nul-terminated strings and handles them appropriate, including converting between them and dynamic strings automagically.
    I only see RTrim$(path, $Nul) where someone has copy/pasted VB code without understanding what they are doing (VB doesn't understand. null terminated strings)

    And as you also recognise, trimming colons and backslashes from the return value of SHGETFOLDERPATH situation is pointless
    (but that's not what your second code snippet is doing)

    Also note that you may require either a STRINGZ (old, inaccurate and depreciated name ASCIIZ) or a WSTRINGZ variable depending on whether or not you have %UNICODE = 1 before #INCLUDE "Win32api.inc"

    And finally:
    NOTE:
    As of Windows Vista, this function is merely a wrapper for SHGetKnownFolderPath. The CSIDL value is translated to its associated KNOWNFOLDERID and then SHGetKnownFolderPath is called. New applications should use the known folder system rather than the older CSIDL system, which is supported only for backward compatibility.



    Comment


    • #3
      Thanks Stuart. There might be a few holdout XP users so I think I'll stick with SHGetFolderPath for now even if it is a wrapper.
      Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

      Comment


      • #4
        old, inaccurate and depreciated name ASCIIZ) or a WSTRINGZ variable
        I do not see in help where ASCIIZ is explicitly deprecated, although the 10.0.4 help (index entry 'ASCIIZ' ) certainly emphasizes the "new" form STRINGZ.

        To me if you are going to have a WSTRINGZ, you need the ASCIIZ type to discriminate between the DBCS and SBCS versions. But to each his own.

        As far as
        depending on whether or not you have [ the %UNICODE equate defined] before #INCLUDE "Win32api.inc"
        I have posted this before but it's still valid..

        Code:
        REM  ** OPTIONAL LINE FOLLOWS **
           %UNICODE =   123    
        ....
        
        #IF %DEF(%UNICODE)
            MACRO BSTR   =     WSTRING
            MACRO ZSTR   =     WSTRINGZ
        #ELSE
                  MACRO BSTR = STRING
                  MACRO ZSTR = ASCIIZ                   ' or whatever floats your boat here
        #ENDIF
        ....
        
        FUNCTION Foo  
          LOCAL     A  AS  BSTR    ' dynamic string
          LOCAL     Z   AS ZSTR    ' null-terminated string
        
                  A  = "My Dog has "
                  Z = "Fleas"
        
        ..

        Now all your user written procedures may be used with EITHER SBCS or WIDE strings without change!

        Yes this is capitalizing on PB's ultra-programmer-friendly handling of same.. but that's why we invest in a specific compiler product!

        I used a similar MACRO for a datatype when I did some coding for the Haru library... which used an "HPDF_REAL" type in the "c' header... but I could not figure out what an "HPDF_REAL" was until I tested .. so I wrote it this way. (Turns out it was a PB SINGLE)

        MCM


        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X