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 / .NET Framework / General / March 2006

Tip: Looking for answers? Try searching our database.

Special Folders in VB 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DCC - 29 Mar 2006 23:52 GMT
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
Mattias Sjögren - 30 Mar 2006 06:14 GMT
>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

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

DCC - 30 Mar 2006 18:31 GMT
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?

> >I need to resolve Windows special folders.  From what I have read it would
> >seem that using CSIDL's and SHGetSpecialFolderPath and SHGetFolderPath was
[quoted text clipped - 5 lines]
>
> Mattias
Mattias Sjögren - 30 Mar 2006 22:26 GMT
>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

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


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.