Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / March 2005

Tip: Looking for answers? Try searching our database.

VS Macros and FolderBrowserDialog

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Henning v. Zitzewitz - 14 Mar 2005 08:13 GMT
Hi,

i'am new to IDE Macro porgramming (and new to VB and .net as well) and stuck
with a problem with FolderBrowserDialog and SHGetPathFromIDList .
I Like to open a "Browse for Folder Dialog" from within a .NET Macro. At
first i tried FolderBrowserDialog but i get an empty dialog, only showing
the OK and Cancel buttons but no treeview for choosing the folder. This is
the code (WinWrapper is copied from the Macro examples):

------------------------------------
Public Class WinWrapper
Implements System.Windows.Forms.IWin32Window
Overridable ReadOnly Property Handle() As System.IntPtr Implements
System.Windows.Forms.IWin32Window.Handle
       Get
           Dim iptr As New System.IntPtr(DTE.MainWindow.HWnd)
           Return iptr
       End Get
   End Property
End Class

Sub testFolderBrowser()
   Dim winptr As New WinWrapper
   Dim folderDialog As New FolderBrowserDialog
   folderDialog.RootFolder = Environment.SpecialFolder.Desktop
   folderDialog.ShowNewFolderButton = False
   If folderDialog.ShowDialog(winptr) = DialogResult.OK Then
       MsgBox(folderDialog.SelectedPath())
   End If
End Sub
------------------------------

Then i tried the SHBrowseForFolder und SHGetPathFromIDList functions
directly:

------------------------------------
Private Structure BrowseInfo
   Public hWndOwner As Long
   Public pIDLRoot As Long
   Public pszDisplayName As Long
   Public lpszTitle As Long
   Public ulFlags As Long
   Public lpfnCallback As Long
   Public lParam As Long
   Public iImage As Long
End Structure

Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_DONTGOBELOWDOMAIN = 2
Private Const MAX_PATH = 260

Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function SHBrowseForFolder Lib "shell32" (ByVal lpbi As
BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As
Long, ByVal lpBuffer As String) As Long
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal
lpString1 As String, ByVal lpString2 As String) As Long

Public Function BrowseForFolder(ByVal hwndOwner As Long, ByVal sPrompt As
   String) As String
   Dim lpIDList As Long ' Declare Varibles
   Dim sBuffer As String
   Dim tBrowseInfo As BrowseInfo
   With tBrowseInfo
       .hWndOwner = hwndOwner ' Owner Form
       .lpszTitle = lstrcat(sPrompt, "")
       .ulFlags = BIF_RETURNONLYFSDIRS + BIF_DONTGOBELOWDOMAIN
   End With
   lpIDList = SHBrowseForFolder(tBrowseInfo)
   If (lpIDList) Then
       sBuffer = Space(MAX_PATH)
       SHGetPathFromIDList(lpIDList, sBuffer)
       sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
       MsgBox(sBuffer)
   End If
End Function
------------------------------------

but this didn't work either. The dialog opens and i can choose a folder but
when i try to get the name with SHGetPathFromIDList() an exception is
thrown. It is something like "an object refernce is not tied to an object
instance". This sounds like a dereferenced NULL pointer to me (i'am a c++
programmer).

Do you have any ideas for solving the problem?

TIA, Henning
amadouN@gmail.com - 14 Mar 2005 19:20 GMT
your are using a function without return any string

> Hi,
>
[quoted text clipped - 84 lines]
>
> TIA, Henning

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.