Click here to Skip to main content
15,921,989 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Question(LPCWSTR) -> (LPSTR) error! Pin
mostafa_pasha6-Sep-06 8:28
mostafa_pasha6-Sep-06 8:28 
QuestionRe: (LPCWSTR) -> (LPSTR) error! Pin
David Crow6-Sep-06 8:32
David Crow6-Sep-06 8:32 
AnswerRe: (LPCWSTR) -> (LPSTR) error! Pin
mostafa_pasha6-Sep-06 8:34
mostafa_pasha6-Sep-06 8:34 
GeneralRe: (LPCWSTR) -> (LPSTR) error! Pin
David Crow6-Sep-06 8:43
David Crow6-Sep-06 8:43 
GeneralRe: (LPCWSTR) -> (LPSTR) error! Pin
Zac Howland6-Sep-06 8:45
Zac Howland6-Sep-06 8:45 
GeneralRe: (LPCWSTR) -> (LPSTR) error! Pin
mostafa_pasha6-Sep-06 9:05
mostafa_pasha6-Sep-06 9:05 
GeneralRe: (LPCWSTR) -> (LPSTR) error! Pin
Hamid_RT6-Sep-06 22:38
Hamid_RT6-Sep-06 22:38 
QuestionGetting the app data folder in Vista Pin
Christopher Duncan6-Sep-06 7:45
Christopher Duncan6-Sep-06 7:45 
Hey, guys.

I have a routine to get the appdata folder that's Vista aware. However, I don't have Vista installed, so I can't test the call to SHGetFolderPathEx, or the REFKNOWNFOLDERID flag that it requires. Anyone here with the Vista dev environment installed who's brave enough to test a function for me? Big Grin | :-D It's VC++, so you should be able to just paste the routine into a test app & call it. Well, you know, theoretically... Roll eyes | :rolleyes:

Here's the code. I've also included the function to get the current version of Windows so that it'll all compile.

//##########<br />
typedef enum<br />
//##########<br />
{<br />
	eUtilsWinVerUnknown,<br />
	eUtilsWinVerWindows95,<br />
	eUtilsWinVerWindows98,<br />
	eUtilsWinVerWindowsMe,<br />
	eUtilsWinVerWindowsNT351,<br />
	eUtilsWinVerWindowsNT400,<br />
	eUtilsWinVerWindows2000,<br />
	eUtilsWinVerWindowsXP,<br />
	eUtilsWinVerWindowsServer2003Family,<br />
	eUtilsWinVerWindowsVista<br />
}UtilsWinVer;<br />
<br />
<br />
/******************************************************************************<br />
dwMajorVersion:<br />
3		Windows NT 3.51 <br />
4		Windows 95 <br />
4		Windows 98 <br />
4		Windows Me <br />
4		Windows NT 4.0 <br />
5		Windows 2000 <br />
5		Windows XP <br />
5		Windows Server 2003 family <br />
6		Windows Server "Longhorn" <br />
6		Windows Vista<br />
<br />
dwMinorVersion:<br />
0		Windows 95 <br />
10		Windows 98 <br />
90		Windows Me <br />
51		Windows NT 3.51 <br />
0		Windows NT 4.0 <br />
0		Windows 2000 <br />
1		Windows XP <br />
2		Windows Server 2003 family <br />
0		Windows Server "Longhorn" <br />
0		Windows Vista (shares 6.0 with Longhorn and so not included in enum)<br />
<br />
dwPlatformId:<br />
VER_PLATFORM_WIN32s 		Win32s on Windows 3.1. <br />
VER_PLATFORM_WIN32_WINDOWS 	Windows 95, Windows 98, or Windows Me. <br />
VER_PLATFORM_WIN32_NT 		Windows NT, Windows 2000, Windows XP, or Windows Server 2003 family. <br />
******************************************************************************/<br />
UtilsWinVer GetWindowsVersion()<br />
{<br />
	UtilsWinVer eVersion = eUtilsWinVerUnknown;<br />
	<br />
	bool bStat = false;<br />
	OSVERSIONINFO VersionInfo;<br />
	ZeroMemory(&VersionInfo, sizeof(OSVERSIONINFO));<br />
	VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br />
	if (GetVersionEx(&VersionInfo))<br />
	{<br />
		switch (VersionInfo.dwMajorVersion)<br />
		{<br />
			case 3:<br />
				if (51 == VersionInfo.dwMinorVersion)<br />
				{<br />
					eVersion = eUtilsWinVerWindowsNT351;<br />
				}<br />
				break;<br />
				<br />
			case 4:<br />
				switch (VersionInfo.dwMinorVersion)<br />
				{<br />
					case 0:<br />
						if (VER_PLATFORM_WIN32_WINDOWS == VersionInfo.dwPlatformId)<br />
						{<br />
							eVersion = eUtilsWinVerWindows95;<br />
						}<br />
						else if (VER_PLATFORM_WIN32_NT == VersionInfo.dwPlatformId)<br />
						{<br />
							eVersion = eUtilsWinVerWindowsNT400;<br />
						}<br />
						else<br />
						{<br />
							// Win 3.1 running win32, default to unknown<br />
						}<br />
						break;<br />
						<br />
					case 10:<br />
						eVersion = eUtilsWinVerWindows98;<br />
						break;<br />
						<br />
					case 90:<br />
						eVersion = eUtilsWinVerWindowsMe;<br />
						break;<br />
						<br />
					default:<br />
						// unknown<br />
						break;<br />
				}<br />
				break;<br />
				<br />
			case 5:<br />
				switch (VersionInfo.dwMinorVersion)<br />
				{<br />
					case 0:<br />
						eVersion = eUtilsWinVerWindows2000;<br />
						break;<br />
						<br />
					case 1:<br />
						eVersion = eUtilsWinVerWindowsXP;<br />
						break;<br />
						<br />
					case 2:<br />
						eVersion = eUtilsWinVerWindowsServer2003Family;<br />
						break;<br />
						<br />
					default:<br />
						// unknown<br />
						break;<br />
				}<br />
				break;<br />
				<br />
			case 6:<br />
				if (0 == VersionInfo.dwMinorVersion)<br />
				{<br />
					eVersion = eUtilsWinVerWindowsVista;<br />
				}<br />
				break;<br />
		}<br />
	}<br />
	return (eVersion);<br />
}	<br />
<br />
/******************************************************************************<br />
******************************************************************************/<br />
CString GetAppDataPath()<br />
{<br />
	// insure that we'll have a valid path<br />
	CString strAppPath = "C:";<br />
	<br />
	HWND hwndOwner = NULL;<br />
    int iFolder = CSIDL_APPDATA | CSIDL_FLAG_CREATE;<br />
    HANDLE hToken = NULL;<br />
    DWORD dwFlags = 0;<br />
	TCHAR szPath[MAX_PATH];<br />
	UtilsWinVer eWinVer = GetWindowsVersion();<br />
	if (eUtilsWinVerWindowsVista == eWinVer)<br />
	{<br />
		// set this to the proper value from the Vista SDK<br />
		// #define REFKNOWNFOLDERID	1<br />
		<br />
		// hack so we'll compile<br />
		DWORD REFKNOWNFOLDERID = 1;<br />
			<br />
		// can't find documentation on the params, so assuming they're the same as SHGetFolderPath()<br />
		typedef HRESULT	(__stdcall *PFNSHGETFOLDERPATHEX)(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);<br />
	<br />
		// Vista<br />
		// http://windowssdk.msdn.microsoft.com/en-us/library/ms708427.aspx<br />
		<br />
		// since SHGetFolderPathEx won't compile pre-Vista, we need to <br />
		// manually load the library to keep the code portable. we'll also <br />
		// need someone with the Vista SDK installed to tell us the value of <br />
		// REFKNOWNFOLDERID, and #define it to the appropriate value<br />
		HMODULE hLib = LoadLibrary("MSI.DLL");<br />
		if (hLib)<br />
		{<br />
			PFNSHGETFOLDERPATHEX lpfnSHGetFolderPathEx = (PFNSHGETFOLDERPATHEX)GetProcAddress(hLib, "SHGetFolderPathEx");<br />
			if (lpfnSHGetFolderPathEx)<br />
			{<br />
				dwFlags = REFKNOWNFOLDERID;<br />
				if (SUCCEEDED(lpfnSHGetFolderPathEx(hwndOwner, <br />
													iFolder, <br />
													hToken,<br />
													dwFlags, <br />
													szPath)))<br />
				{<br />
					strAppPath = szPath;<br />
				}<br />
			}<br />
		}<br />
	}<br />
	else<br />
	{<br />
		// XP and all those other, lesser, operating systems...<br />
		if (SUCCEEDED(SHGetFolderPath(hwndOwner, <br />
		                             iFolder, <br />
									 hToken,<br />
		                             dwFlags, <br />
		                             szPath)))<br />
		{<br />
			strAppPath = szPath;<br />
		}<br />
	}<br />
	return (strAppPath);<br />
}<br />




QuestionCan't compile an aplication with WinHTTP Pin
Eugene Pustovoyt6-Sep-06 7:38
Eugene Pustovoyt6-Sep-06 7:38 
AnswerRe: Can't compile an aplication with WinHTTP Pin
prasad_som6-Sep-06 21:18
prasad_som6-Sep-06 21:18 
AnswerRe: Can't compile an aplication with WinHTTP Pin
Hamid_RT11-Sep-06 9:42
Hamid_RT11-Sep-06 9:42 
QuestionFile extentions in vc++ Pin
amaneet6-Sep-06 6:43
amaneet6-Sep-06 6:43 
AnswerRe: File extentions in vc++ Pin
Maximilien6-Sep-06 6:47
Maximilien6-Sep-06 6:47 
QuestionRe: File extentions in vc++ Pin
David Crow6-Sep-06 7:45
David Crow6-Sep-06 7:45 
AnswerRe: File extentions in vc++ Pin
Hamid_RT7-Sep-06 9:06
Hamid_RT7-Sep-06 9:06 
QuestionA not so simple define Pin
Waldermort6-Sep-06 5:24
Waldermort6-Sep-06 5:24 
QuestionRe: A not so simple define Pin
David Crow6-Sep-06 5:51
David Crow6-Sep-06 5:51 
AnswerRe: A not so simple define Pin
Waldermort6-Sep-06 6:17
Waldermort6-Sep-06 6:17 
GeneralRe: A not so simple define Pin
David Crow6-Sep-06 7:43
David Crow6-Sep-06 7:43 
GeneralRe: A not so simple define Pin
Waldermort6-Sep-06 7:53
Waldermort6-Sep-06 7:53 
AnswerRe: A not so simple define Pin
led mike6-Sep-06 6:56
led mike6-Sep-06 6:56 
GeneralRe: A not so simple define Pin
Waldermort6-Sep-06 7:48
Waldermort6-Sep-06 7:48 
QuestionQuestion Pin
led mike6-Sep-06 8:53
led mike6-Sep-06 8:53 
AnswerRe: A not so simple define Pin
Zac Howland6-Sep-06 8:42
Zac Howland6-Sep-06 8:42 
GeneralRe: A not so simple define Pin
Waldermort6-Sep-06 13:54
Waldermort6-Sep-06 13:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.