Special Folders in VB 2005

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to resolve Windows special folders. From what I have read it would
seem that using CSIDL's and SHGetSpecialFolderPath and SHGetFolderPath was
the way to accomplish that in VB6 and VB.NET. Is this still the best method
in VB 2005? If so does anyone have a working example of how to declare and
call the functions?

I have tried declaring the functions as follows:

Private Declare Function SHGetFolderPath Lib "shell32.dll" _
Alias "SHGetFolderPathA" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, _
ByVal hToken As Long, ByVal dwFlags As Long, _
ByVal pszPath As String) As Long

Private Declare Function SHGetSpecialFolderPath Lib "shell32.dll" _
Alias "SHGetSpecialFolderPathA" _
(ByVal hwndOwner As Long, ByVal pszPath As String, _
ByVal nFolder As Long, ByVal fCreate As Long) As Long


And then to get the name of a directory i tried calling the functions like
this:

dim lTmp as Long

lTmp = SHGetFolderPath(Me.Handle, CSIDL_FAVORITES, 0, SHGFP_TYPE_CURRENT,
sPath)

lTmp = SHGetSpecialFolderPath(Me.Handle, sPath, CSIDL_FAVORITES, 0)

But I get an error saying that "a call to PInvoke has unbalanced the stack"

Everything I have been able to find on help sites says that the first
argument to those functions should be Me.hWnd but VB 2005 doesnt seem to
recognize Me.hWnd so I tried Me.Handle because it recognizes that.

If this is not the right approach and there is a better way please let me
know.

Thanks
 
I need to resolve Windows special folders. From what I have read it would
seem that using CSIDL's and SHGetSpecialFolderPath and SHGetFolderPath was
the way to accomplish that in VB6 and VB.NET. Is this still the best method
in VB 2005?

No, use System.Environment.GetFolderPath if the foilder you want is in
the SpecialFolder enumeration.


Mattias
 
Thanks for the response! I'll attempt to impliment the method you suggested.

Question though: The list of CSIDLs seems much more extensive than what's
exposed by System.Environment.GetFolderPath. Although many of the values
don't seem useful at this point, how would I go about handling CSIDLs if I
needed a value that's not available through System.Environment.GetFolderPath?
 
how would I go about handling CSIDLs if I
needed a value that's not available through System.Environment.GetFolderPath?

Then you're back to using functions like SHGetFolderPath. If you want
to do so, you must correct your declarations. The ones you posted were
probably written for VB6 and wont work in VB.NET. Try to find correct
ones at www.pinvoke.net.


Mattias
 
Back
Top