Announcement

Collapse
No announcement yet.

My Documents

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

  • My Documents

    I knwo this question has come up before, but a shortcut answer will work too.

    I want to know hte users My Documents folder.

    On NT this is easy, ENVIRON$("HOMEPATH").
    On 98 it *may* vary depending if there are profiles or not...


    There's the api for getting a TEMP directory, is there one for My Documents?


    I dont' want to assume c:\my documents for two reasons, #1 it may not be ON C:\ it maybe on D:\ and because if there are profiles it may change (??? Not sure if that folder does on 98 or not)...


    Thanks,

    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Check out the SHGetSpecialFolderLocation() API - search the BBS and you should find some code for this.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      So is this a COM function?
      Will I need to go through this hoop too?
      CoCreateInstance


      Egads...I don't quite understand what I'm doing, got the code and can look at it, but I just want to retrieve the path..

      Something is telling me this might be part of it:

      Code:
              If IsFalse(SHGetSpecialFolderLocation(ByVal %HWND_DESKTOP, ByVal CSIDL, ByVal VarPtr(pidl))) Then
                  SHGetPathFromIDList ByVal pidl, TmpAsciiz
                  CoTaskMemFree ByVal pidl
              End If

      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        > Something is telling me this might be part of it
        It's not a part - it's completed code

        Another question that maybe it's better to add CoInitialize at the top of program and CoUninitialize at the end.
        I always do so, unlike SHGetSpecialFolderLocation will work and w/o these statements.

        Code:
           #Compile Exe
           #Dim All
           #Register None
           #Include "Win32Api.Inc"
        
           Declare Function CoInitialize Lib "ole32.dll" Alias "CoInitialize" _
              (ByVal pvReserved As Dword) As Dword
           Declare Sub CoUninitialize Lib "ole32.dll" Alias "CoUninitialize"
           Declare Function CoTaskMemAlloc Lib "ole32.dll" Alias "CoTaskMemAlloc" (ByVal Dword) As Dword
           Declare Sub CoTaskMemFree Lib "ole32.dll" Alias "CoTaskMemFree" (pv As Dword)
        
           Function SpecialFolder(CSIDL As Long) As String
              Dim pidl As Dword, TmpAsciiz As Asciiz * %MAX_PATH
              If IsFalse(SHGetSpecialFolderLocation(ByVal %HWND_DESKTOP, ByVal CSIDL, ByVal VarPtr(pidl))) Then _
                 SHGetPathFromIDList ByVal pidl, TmpAsciiz: CoTaskMemFree ByVal pidl: Function = TmpAsciiz
           End Function
        
           Function PbMain
              CoInitialize 0
              MsgBox SpecialFolder(%CSIDL_PERSONAL)
              CoUninitialize
           End Function
        [This message has been edited by Semen Matusovski (edited February 12, 2001).]

        Comment


        • #5
          This works like a charm! Even on Win2k

          I just modified it slightly to my own tastes, very good tho!! Thanks

          Scott
          Code:
          #Compile Exe
          #Dim All
          #Register None
          #Include "Win32Api.Inc"
          
          Declare Function CoInitialize Lib "ole32.dll" Alias "CoInitialize"(ByVal pvReserved As Dword) As Dword
          Declare Sub CoUninitialize Lib "ole32.dll" Alias "CoUninitialize"
          Declare Function CoTaskMemAlloc Lib "ole32.dll" Alias "CoTaskMemAlloc" (ByVal Dword) As Dword
          Declare Sub CoTaskMemFree Lib "ole32.dll" Alias "CoTaskMemFree" (pv As Dword)
          
          Function SpecialFolder() As String
          Dim pidl As Dword
          Dim TmpAsciiz As Asciiz * %MAX_PATH
          CoInitialize 0
          If IsFalse(SHGetSpecialFolderLocation(ByVal %HWND_DESKTOP, ByVal %CSIDL_PERSONAL, ByVal VarPtr(pidl))) Then
             SHGetPathFromIDList ByVal pidl, TmpAsciiz: CoTaskMemFree ByVal pidl
          End If
          Function = TmpAsciiz
          CoUninitialize
          End Function
          
          Function PbMain
          MsgBox SpecialFolder
          End Function

          ------------------
          Scott
          mailto:[email protected][email protected]</A>
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            Question, is this safe to do?
            The function assumes a return, and even if a return does not come do you still not have to TaskMemFree???

            Function DocumentFolder() As String
            Dim pidl As Dword
            Dim TmpAsciiz As Asciiz * %MAX_PATH
            CoInitialize 0
            If IsFalse(SHGetSpecialFolderLocation(ByVal %HWND_DESKTOP, ByVal %CSIDL_PERSONAL, ByVal VarPtr(pidl))) Then
            SHGetPathFromIDList ByVal pidl, TmpAsciiz
            End If
            CoTaskMemFree ByVal pidl
            CoUninitialize
            Function = TmpAsciiz & "\"
            End Function

            [This message has been edited by Scott Turchin (edited February 12, 2001).]
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment


            • #7
              Maybe PB can shed some light on this.
              Is CoInitialize already called on app execution?

              It seems so with Depends..
              (Maybe i'm mistaken)

              ------------------
              hellobasic

              Comment


              • #8
                Edwin --
                CoInitialize is not called automatic (I tested return value).
                Another question - is it necessary or not.

                Situation looks like with InitCommonControls.
                At least some controls can work without it.
                But - to be sure - I use InitCommonControls anyway.

                Scott --
                If function fails, pidl doesn't exist, so no reason to memfree.


                ------------------
                E-MAIL: [email protected]

                Comment

                Working...
                X