Cant we develope a dll which can be work in both vista and XP?
-
Hi All, We have one dll which can be used in many Exes and different Operating systems. At present i am having one requirement to support to get the LocalLow path in vista. So I have implemented separate function for it. I have used SHGetKnownFolderPath funciton to get the LocalLow path. To compile the workspace , I have to use WINVER value as 0x0600. IF we defined the WinVersion as 6 , DLL is not running in XP. Developement Environment :VS 2005 & Vista Business. //In Vista Expected output : C:\Users\bob\AppData\LocalLow\eGrabber\ //In XP Expceted output: C:\Documents and Settings\Smith\Application Data\eGrabber\
int GetCurrentUserLocalLowAppPath(LPTSTR szProfileDir,int dirlen ) { memset(szProfileDir,0,dirlen); if(IsWinXP() == TRUE) { GetCurrentUserAppPath( szProfileDir, dirlen ); } else if(IsVista() == TRUE) { PWSTR pszPath[1]; SHGetKnownFolderPath(NULL,FOLDERID_LocalAppDataLow,0,NULL,pszPath); //copying the pszPath to szProfileDir array } return 1; }
Any idea how to achieve this. Your suggestion welcomed ... Thanks. -
Hi All, We have one dll which can be used in many Exes and different Operating systems. At present i am having one requirement to support to get the LocalLow path in vista. So I have implemented separate function for it. I have used SHGetKnownFolderPath funciton to get the LocalLow path. To compile the workspace , I have to use WINVER value as 0x0600. IF we defined the WinVersion as 6 , DLL is not running in XP. Developement Environment :VS 2005 & Vista Business. //In Vista Expected output : C:\Users\bob\AppData\LocalLow\eGrabber\ //In XP Expceted output: C:\Documents and Settings\Smith\Application Data\eGrabber\
int GetCurrentUserLocalLowAppPath(LPTSTR szProfileDir,int dirlen ) { memset(szProfileDir,0,dirlen); if(IsWinXP() == TRUE) { GetCurrentUserAppPath( szProfileDir, dirlen ); } else if(IsVista() == TRUE) { PWSTR pszPath[1]; SHGetKnownFolderPath(NULL,FOLDERID_LocalAppDataLow,0,NULL,pszPath); //copying the pszPath to szProfileDir array } return 1; }
Any idea how to achieve this. Your suggestion welcomed ... Thanks.The only problem for not working the dll in windows XP is that, it is using a function(
SHGetKnownFolderPath
), that is not available in windows XP. To solve this problem, instead of statically linking to the SHGetKnownFolderPath() function, dynamically call it. That is, using theLoadLibrary()
andGetProcAddress()
functions. -
The only problem for not working the dll in windows XP is that, it is using a function(
SHGetKnownFolderPath
), that is not available in windows XP. To solve this problem, instead of statically linking to the SHGetKnownFolderPath() function, dynamically call it. That is, using theLoadLibrary()
andGetProcAddress()
functions.Thanks Naveen. Here is the code for it.
typedef HRESULT (WINAPI * SHGetKnownFolderPathFn)(REFKNOWNFOLDERID rfid, DWORD dwFlags, HANDLE hToken,PWSTR *ppszPath);
PWSTR pszPath\[1\]; SHGetKnownFolderPathFn shGetKnownFolrPth = NULL ; HINSTANCE hins = LoadLibrary("Shell32.dll");
if(hins != NULL)
{shGetKnownFolrPth = (SHGetKnownFolderPathFn)::GetProcAddress(hins,"SHGetKnownFolderPath");
if( shGetKnownFolrPth != NULL) { shGetKnownFolrPth(FOLDERID\_LocalAppDataLow,0,NULL,pszPath); CString csData=pszPath\[0\]; // converting from wchar to ANSI. } }