Announcement

Collapse
No announcement yet.

Windows special folders

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

  • Windows special folders

    I am trying to access the windows special folders (eg. desktop
    folder), how can I do that with PowerBASIC-Code ?

    When I'm able to access the desktop folder how can I create a
    link to a program ?

    An example would be appreciated.

    ------------------

  • #2
    I"m sorry your post did not get answered, but since we've been discussing this let me toss a couple of functions your way in case you didnt' see them.


    This returns the My Documents folder, and the second function will create the link, but that is more difficult to understand (I still get confused by it sometimes).


    Code:
    Declare Function DocumentFolder() As String  
    '-----------------------------------------------------------------------------------------
    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
    '-----------------------------------------------------------------------------------------
    
    
    '
    '
    Declare Function CreateLink (ByVal CSIDL As Long, LnkName As Asciiz, _
                    ExePath As Asciiz, Arguments As Asciiz, WorkDir As Asciiz, _
                    ByVal ShowCmd As Dword, Comment As Asciiz) As Long
    
    Declare Function CoInitialize Lib "ole32.dll" Alias "CoInitialize" _
                    (ByVal pvReserved As Dword) As Dword
    Declare Function CoCreateInstance Lib "ole32.dll" Alias "CoCreateInstance" _
                    (rclsid As String * 16, ByVal pUnkOuter As Any, ByVal dwClsContext As Dword, _
                     riid As String * 16, ppv As Dword) As Dword
    Declare Sub CoUninitialize Lib "ole32.dll" Alias "CoUninitialize"
    Declare Sub CoTaskMemFree Lib "ole32.dll" Alias "CoTaskMemFree" (pv As Dword)
    Declare Function ComSub1 (p1 As Any) As Dword
    Declare Function ComSub2 (p1 As Any, p2 As Any) As Dword
    Declare Function ComSub3 (p1 As Any, p2 As Any, p3 As Any) As Dword
    
    'Now to create the link:
    Local TargetEXE         As Asciiz * 255
    Local TargetLNKName     As Asciiz * 255
    Local TargetStartDir    As Asciiz * 255
    Local WindirDesktop     As String 
    
        TargetEXE = CurDir$ + "\SHUTDOWN.EXE"
        TargetStartDir = CurDir$
        TargetLNKName = "Shutdown!"
        l_Result = CreateLink(%CSIDL_DESKTOP, TargetLNKName, TargetEXE, _
                "", TargetStartDir, %SW_NORMAL, "")' First "" is commandline params second is Comments
    
    
    '==========================================================================================
    
    Function CreateLink (ByVal CSIDL As Long, LnkName As Asciiz, _
                    ExePath As Asciiz, Arguments As Asciiz, WorkDir As Asciiz, _
                    ByVal ShowCmd As Dword, Comment As Asciiz) As Long
    
    Local TmpAsciiz As Asciiz * %MAX_PATH, TmpWide As Asciiz * (2 * %MAX_PATH)
    Local psl As Dword Ptr, ppf As Dword Ptr, pp As Dword Ptr, lResult As Dword
    Local CLSID_ShellLink As String * 16, IID_IShellLink As String * 16, _
    CLSCTX_INPROC_SERVER As Dword, IID_Persist As String * 16
    CLSID_ShellLink = Mkl$(&H00021401) + Chr$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46)
    IID_IShellLink = Mkl$(&H000214EE) + Chr$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46)
    IID_Persist = Mkl$(&H0000010B) + Chr$(0, 0, 0, 0, &HC0, 0, 0, 0, 0, 0, 0, &H46)
    CLSCTX_INPROC_SERVER = 1
    
    CoInitialize %Null
    If IsFalse(CoCreateInstance (CLSID_ShellLink, %Null, CLSCTX_INPROC_SERVER, IID_IShellLink, psl)) Then
        pp = @psl + 80: Call Dword @pp Using ComSub2 (ByVal psl, ExePath)
        pp = @psl + 44: Call Dword @pp Using ComSub2 (ByVal psl, Arguments)
        pp = @psl + 36: Call Dword @pp Using ComSub2 (ByVal psl, WorkDir)
        pp = @psl + 60: Call Dword @pp Using ComSub2 (ByVal psl, ByVal ShowCmd)
        pp = @psl + 28: Call Dword @pp Using ComSub2 (ByVal psl, Comment)
        pp = @psl: Call Dword @pp Using ComSub3 (ByVal psl, IID_Persist, ppf) To lResult
        If lResult = 0 Then
            Dim pidl As Dword
            TmpAsciiz = CurDir$
            If IsFalse(SHGetSpecialFolderLocation(ByVal %HWND_DESKTOP, ByVal CSIDL, ByVal VarPtr(pidl))) Then
                SHGetPathFromIDList ByVal pidl, TmpAsciiz
                CoTaskMemFree ByVal pidl
            End If
            TmpAsciiz = TmpAsciiz + "\" + LnkName + ".Lnk"
            MultiByteToWideChar %CP_ACP, 0, TmpAsciiz, -1, TmpWide, %MAX_PATH
            pp = @ppf + 24: Call Dword @pp Using ComSub3 (ByVal ppf, TmpWide, ByVal %True)
            pp = @ppf + 8: Call Dword @pp Using ComSub1 (ByVal ppf)
        End If
        pp = @psl + 8: Call Dword @pp Using ComSub1 (ByVal psl)
    End If
    CoUninitialize
    Function = %TRUE
    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


    • #3
      Tank you very much for your example code creating a link. It works
      fine.

      Heinz

      ------------------

      Comment

      Working...
      X