Page 1 of 1

Getting the user's My Documents folder location

Posted: Thu Aug 23, 2007 1:03 am
by Tipperton
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:

Code: Select all

SHGetSpecialFolderPath_(0, @sPath.s{#MAX_PATH}, #CSIDL_MYDOCUMENTS, #False)
MessageRequester("My Documents Location", sPath, #PB_MessageRequester_Ok)
But when I try to compile it I get:
Line 1: SHGetSpecialFolderPath_() is not a function, array, macro or linked list
Huh?? :?

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)
EndIf
It compiles OK but when I run it I get:
Error code: 126
The specified module could not be found.
Huh?? Even more :?

If I use my file viewer on shell32.dll and look through the export list, I find:
316 0x0002F46F SHGetSpecialFolderLocation
317 0x000F8C12 SHGetSpecialFolderPathA
318 0x00031957 SHGetSpecialFolderPathW
319 0x000D4098 SHGetUnreadMailCountW
So the function is there... What gives?

Any ideas? I'm stumped...

Posted: Thu Aug 23, 2007 2:02 am
by SoulReaper
I Believe it is this, I cant understand why it will not work the way you had it...

#CSIDL_PERSONAL

Thats what I used and it seemed to work.

typed it in on google and it said "This value is equivalent to CSIDL_PERSONAL. ... CSIDL_PERSONAL (FOLDERID_Documents)"

I hope this is of some help to you :)

http://msdn2.microsoft.com/en-us/library/ms649274.aspx
Ahh they are both right... see link above...

Regards
Kevin :wink:

Posted: Thu Aug 23, 2007 3:13 am
by Tipperton
D'oh!

I had seen that and thought to try it, but I guess I forgot... :(

Anyway, using #CSIDL_PERSONAL instead of #CSIDL_MYDOCUMENTS worked for the OpenLibrary/CallFunction method.

Still puzzling why the apparently predefined call throws that error though, but at least I can get around that.

Thanks!

Posted: Sat Aug 25, 2007 2:54 pm
by Tipperton
A follow up question on this:
Tipperton wrote: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:

Code: Select all

SHGetSpecialFolderPath_(0, @sPath.s{#MAX_PATH}, #CSIDL_MYDOCUMENTS, #False)
MessageRequester("My Documents Location", sPath, #PB_MessageRequester_Ok)
But when I try to compile it I get:
PureBasic compiler wrote:Line 1: SHGetSpecialFolderPath_() is not a function, array, macro or linked list
I looked in the C:\Program Files\PureBasic\Compilers\APIFunctionListing.txt file and found:
APIFunctionListing.txt wrote:SHGetSpecialFolderLocation (hwndOwner, nFolder, ppidl)
SHGetSpecialFolderPath
SHGlobalDefect
Would I be correct in assuming that since no parameters for SHGetSpecialFolderPath are defined that this API call isn't implemented?

Is this true for all the other API functions listed that also don't have parameters listed?

What I'm trying to do is find out how to know which API calls are implemented and which ones I have to use OpenLibrary/CallFunction to use.

Or is this a bug that should be reported.

Thanks!

Posted: Sat Aug 25, 2007 3:12 pm
by Fluid Byte
Would I be correct in assuming that since no parameters for SHGetSpecialFolderPath() are defined that this API call isn't implemented?
Well, can you call the function from PB? I surely can't. So no, has to be imported.

Posted: Sat Aug 25, 2007 3:25 pm
by Tipperton
Well, that's confusing and pointless....

If it's not implemented as a direct call, it shouldn't be in auto-complete IMHO