[AccessD] IMAllocate

John W. Colby jwcolby at colbyconsulting.com
Mon May 30 06:53:29 CDT 2005


Stuart,

Is there a way to have this dialog present a "new directory" button so that
if a directory doesn't exist it can be created from within the dialog?

John W. Colby
www.ColbyConsulting.com 

Contribute your unused CPU cycles to a good cause:
http://folding.stanford.edu/

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan
Sent: Monday, May 30, 2005 12:21 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] IMAllocate


On 29 May 2005 at 23:59, John W. Colby wrote:

> Is this in something I can reference?  I am trying to get code to 
> browse for folders as opposed to files, and I am up against this ATM.
> 

ShBrowseForFolder() allocates memory automatically for the pidl so you 
don't need to worry about IMAllocate, but you need to clean it up yourself 
afterwards with  CoTaskMemFree.

Here's a simple Folder Browser demo.

Stick this in a module soemwhere:

Public Declare Function SHBrowseForFolder Lib "shell32.dll" _
   Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Public Declare Function SHGetPathFromIDList Lib "shell32.dll" _
   Alias "SHGetPathFromIDListA" _
  (ByVal pidl As Long, _
   ByVal pszPath As String) As Long
    
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)

Public Type BROWSEINFO    'BI
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type


Stick this behind a button on a form:

Private Sub btnBrowseForFolder_Click()
  Dim pidl As Long
  Dim BI As BROWSEINFO
  Dim sPath As String
  Dim pos As Integer
 
  'Fill BROWSEINFO structure data
   With BI
      .hOwner = 0
      .pidlRoot = 0
      .lpszTitle = "Browsing"
      .ulFlags = 1
      .pszDisplayName = Space$(260)
   End With
  
  'show dialog returning pidl to selected item
   pidl = SHBrowseForFolder(BI)
 
  'if pidl is valid, parse & return the user's selection
   sPath = Space$(260)
    
   If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
   
     'SHGetPathFromIDList returns the absolute
     'path to the selected item. No path is returned for virtual folders.
      pos = InStr(sPath, Chr$(0))
      If pos Then Text1 = Left(sPath, pos - 1)
   Else:
     Text1 = "Problem"
   End If
 'free the pidl
   Call CoTaskMemFree(pidl)
        
End Sub
-- 
Stuart


-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com






More information about the AccessD mailing list