Getting the user's My Documents folder location
Posted: Thu Aug 23, 2007 1:03 am
While working on a project, I needed to get the current user's My Documents folder location (path). After looking around in the SDK docs I found SHGetSpecialFolderPath in shell32.dll, perfect!
First I check to see if its a predefined API call by starting to type it in too see if it shows up in autocomplete, it does, so I write:
But when I try to compile it I get:

So I decide to use the OpenLibrary/CallFunction method to access it so I write:
It compiles OK but when I run it I get:

If I use my file viewer on shell32.dll and look through the export list, I find:
Any ideas? I'm stumped...
First I check to see if its a predefined API call by starting to type it in too see if it shows up in autocomplete, it does, so I write:
Code: Select all
SHGetSpecialFolderPath_(0, @sPath.s{#MAX_PATH}, #CSIDL_MYDOCUMENTS, #False)
MessageRequester("My Documents Location", sPath, #PB_MessageRequester_Ok)Huh??Line 1: SHGetSpecialFolderPath_() is not a function, array, macro or linked list
So I decide to use the OpenLibrary/CallFunction method to access it so I write:
Code: Select all
If OpenLibrary(0, "shell32.dll")
If CallFunction(0, "SHGetSpecialFolderPathA", 0, @sPath.s{#MAX_PATH}, #CSIDL_MYDOCUMENTS, #False)
MessageRequester("My Documents Location", sPath, #PB_MessageRequester_Ok)
Else
lLastError.l=GetLastError_()
FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM, #Null, lLastError, 0, @sErrorMessage.s{256}, 256, #Null)
MessageRequester("Error!", "Error code: "+Str(lLastError)+#CRLF$+sErrorMessage, #PB_MessageRequester_Ok)
EndIf
CloseLibrary(0)
EndIfHuh?? Even moreError code: 126
The specified module could not be found.
If I use my file viewer on shell32.dll and look through the export list, I find:
So the function is there... What gives?316 0x0002F46F SHGetSpecialFolderLocation
317 0x000F8C12 SHGetSpecialFolderPathA
318 0x00031957 SHGetSpecialFolderPathW
319 0x000D4098 SHGetUnreadMailCountW
Any ideas? I'm stumped...