S
Sankalp
Hi,
I have a excel add-in that needs to create/copy some files under the
user specific profile. (i.e under C:\Documents and Settings\<current user
profile>\Application Data\<CosName>\Excel\).
The SHGetSpecialFolderLocation and SHGetPathFromIDList are being used to
get the path of user's profile. To this path is appended the the
"CompanyName" and then the "ApplicationName".
Subsequently, the SHCreateDirectory is used to create the necessary
directory. It is here the call fails.
Is it right to use the SHxxxx API's for this purpose? If not, what is
the alternative?
Following is the code snippet:
#include <Shlobj.h>
#include <Shfolder.h>
int main(int argc, char* argv[]) {
LPITEMIDLIST ppidl;
char lpPath[MAX_PATH];
char lpFilePath[MAX_PATH];
HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &ppidl);
if (SUCCEEDED(hr)) {
SHGetPathFromIDList( ppidl, lpPath );
printf( "Application Data: %s\n\n", lpPath );
}
::CoTaskMemFree(ppidl);
strcat(lpPath, "\\CoName\\Excel\\");
printf( "Application Data: %s\n\n", lpPath );
int iStatus = ::SHCreateDirectory(NULL, (LPCWSTR)lpPath); // returns 161 -
ERROR_BAD_PATHNAME
if (ERROR_SUCCESS == iStatus ||
ERROR_FILE_EXISTS == iStatus ||
ERROR_ALREADY_EXISTS == iStatus) {
sprintf(lpFilePath, "%s\\config.dat", lpPath);
printf( "Config file path: %s\n\n", lpFilePath );
// Copy only if the file does NOT exist.
//CopyFile(configfile, lpPath, TRUE);
}
return 0;
}
Thanks,
Sankalp
I have a excel add-in that needs to create/copy some files under the
user specific profile. (i.e under C:\Documents and Settings\<current user
profile>\Application Data\<CosName>\Excel\).
The SHGetSpecialFolderLocation and SHGetPathFromIDList are being used to
get the path of user's profile. To this path is appended the the
"CompanyName" and then the "ApplicationName".
Subsequently, the SHCreateDirectory is used to create the necessary
directory. It is here the call fails.
Is it right to use the SHxxxx API's for this purpose? If not, what is
the alternative?
Following is the code snippet:
#include <Shlobj.h>
#include <Shfolder.h>
int main(int argc, char* argv[]) {
LPITEMIDLIST ppidl;
char lpPath[MAX_PATH];
char lpFilePath[MAX_PATH];
HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &ppidl);
if (SUCCEEDED(hr)) {
SHGetPathFromIDList( ppidl, lpPath );
printf( "Application Data: %s\n\n", lpPath );
}
::CoTaskMemFree(ppidl);
strcat(lpPath, "\\CoName\\Excel\\");
printf( "Application Data: %s\n\n", lpPath );
int iStatus = ::SHCreateDirectory(NULL, (LPCWSTR)lpPath); // returns 161 -
ERROR_BAD_PATHNAME
if (ERROR_SUCCESS == iStatus ||
ERROR_FILE_EXISTS == iStatus ||
ERROR_ALREADY_EXISTS == iStatus) {
sprintf(lpFilePath, "%s\\config.dat", lpPath);
printf( "Config file path: %s\n\n", lpFilePath );
// Copy only if the file does NOT exist.
//CopyFile(configfile, lpPath, TRUE);
}
return 0;
}
Thanks,
Sankalp