How to call SHGetKnownFolderPath function properl
Posted 29 December 2012 - 15:15
I have a problem with my installscript project.
I need to call the "SHGetKnownFolderPath" function but when I build the project there's no error in build. So, I test the build but when this takes some part of the installation then an error appears: "error in call "SHGetKnownFolderPath".
CODE |
// Define Microsoft CSIDL constants #define FOLDERID_SavedGames #define KF_FLAG_DONT_VERIFY 0x00004000 // Prototype SHGetFolderPathA in SHFolder.dll prototype NUMBER shell32.SHGetKnownFolderPath(HWND, NUMBER, NUMBER, BYREF STRING); szPath = ""; nResult=shell32.SHGetKnownFolderPath(FOLDERID_SavedGames, KF_FLAG_DONT_VERIFY, NULL, szPath); if (nResult=0) then MessageBox("FOLDERID_SavedGames= "+szPath,0); else SprintfBox(SEVERE, "FOLDERID_SavedGames", "Failed(%d): %s", nResult, FormatMessage(nResult)); endif; |
Please, Anyone to help me?, thanks.
P.D. This is the error code:
Error Number: 0x80040707 Failure to call the function
Edited by thanatos83, 30 December 2012 - 16:50.
Posted 02 January 2013 - 16:07
Edited by Taco Bell, 02 January 2013 - 16:08.
Posted 03 January 2013 - 11:48
OK, I modified the script and when compiling only one error was reported:
comma expected in 0hff325c4c9dbbb043b5b42d72e54eaaa4
but this is the reference when define the constant so whats the problem?
CODE |
// Define Microsoft CSIDL constants for Vista #define FOLDERID_SavedGames 0hff325c4c9dbbb043b5b42d72e54eaaa4 // Prototype SHGetKnownFolderPath in Shell32 prototype NUMBER shell32.SHGetKnownFolderPath( NUMBER, NUMBER, HWND, BYREF STRING); nResult=shell32.SHGetKnownFolderPath( FOLDERID_SavedGames, 0, NULL, szPath); if (nResult=0) then MessageBox("CSIDL_COMMON_FAVORITES= "+szPath,0); else SprintfBox(SEVERE, "CSIDL_COMMON_FAVORITES", "Failed(%d): %s", nResult, FormatMessage(nResult)); endif; |
Posted 03 January 2013 - 14:06
Also, I looked into it further and that newer SHGetKnownFolderPath function call surprisingly doesn't have ANSI & Unicode counterparts, so you can ignore my previous suggestion.
Edited by Taco Bell, 03 January 2013 - 14:28.
Posted 03 January 2013 - 16:25
QUOTE |
Also, I looked into it further and that newer SHGetKnownFolderPath function call surprisingly doesn't have ANSI & Unicode counterparts, so you can ignore my previous suggestion. |
Understood.
I looked MSDN documentation too and yes I need to set that GUID value but when you define this GUID value you need to enclose with quotes?
CODE |
// Define Microsoft CSIDL constants for Vista #define FOLDERID_SavedGames "{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}" // Prototype SHGetKnownFolderPath in Shell32 prototype NUMBER shell32.SHGetKnownFolderPath( NUMBER, NUMBER, HWND, BYREF STRING); |
Edited by thanatos83, 03 January 2013 - 16:29.
Posted 04 January 2013 - 14:47
Posted 04 January 2013 - 15:22
Stefan Krüger
InstallSite.org twitter facebook
Posted 04 January 2013 - 15:27
Stefan Krüger
InstallSite.org twitter facebook
Posted 04 January 2013 - 15:31
Stefan Krüger
InstallSite.org twitter facebook
Posted 04 January 2013 - 16:05
QUOTE |
Oh, and SHGetKnownFolderPath requires Windows Vista or above. If you also want to support XP you'd better call SHGetFolderPath which takes an INT parameter (CSIDL) to specify which folder you want to retrieve http://msdn.microsof...1(v=vs.85).aspx |
Thanks for suggestion about to support XP Stefan, I'll take in mind.
The first parameter in the prototype is NOT a number (you're right) because string variables passed to DLL functions are passed by reference. In that case I need to use that type of value: "BYREF STRING"
But when compiling there are errors related to character "{", unreconized character, etc..
Edited by thanatos83, 04 January 2013 - 16:08.
Posted 08 January 2013 - 12:42
Maybe try and assign the contant to a variable, like this:
#define FOLDERID_SavedGames "{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}"
szSavedGames = FOLDERID_SavedGames;
and then use szSavedGames in the first parameter.
Stefan Krüger
InstallSite.org twitter facebook
Posted 09 January 2013 - 20:57
Failed --> the system can not find the file specified.
CODE |
// Define Microsoft GUID constant for Vista #define FOLDERID_SavedGames "{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}" // Prototype SHGetKnownFolderPath in Shell32 prototype NUMBER Shell32.SHGetKnownFolderPath( BYREF STRING, NUMBER, HWND, BYREF STRING); szSavedGames = FOLDERID_SavedGames; nResult = Shell32.SHGetKnownFolderPath( szSavedGames, 0, NULL, szPath ); if (nResult=0) then MessageBox("FOLDERID_SavedGames= "+szPath,0); else SprintfBox(SEVERE, "FOLDERID_SavedGames=", "Failed(%d): %s" nResult, FormatMessage(nResult)); endif; |
I think the problem resides in the final parameter...
Edited by thanatos83, 10 January 2013 - 16:11.
Posted 10 January 2013 - 18:52
Stefan Krüger
InstallSite.org twitter facebook
Posted 11 January 2013 - 16:02
Yes, so this is the result from Process Monitor... and only is filtered with file system activity and only setup.exe process.
I attached the image from process monitor but it seems the error points to a diferent path
Edited by thanatos83, 11 January 2013 - 16:05.
Posted 11 January 2013 - 17:45
You could try writing your own DLL to call the function, and then pass the result back to InstallShield. This would also help to find out if the problem is in InstallShield or in the parameters for the function call.
Stefan Krüger
InstallSite.org twitter facebook
Posted 18 January 2013 - 08:30
I'll try that, thanks.
Posted 23 January 2013 - 19:22
Stefan Krüger
InstallSite.org twitter facebook
Posted 23 January 2013 - 20:51
Q111348: CODE: Find the Directory Where Internet Favorite Items Are Stored
Edited by thanatos83, 23 January 2013 - 20:58.