Originally Posted by
Elysia
Are you using unicode?
OMG! You're Right. I made An "Unforgivable Mistake" Attachment 7780
All of the previous functions works on Windows 98 just fine. And here is the code to test it :
Code:
#include <windows.h>
#include <stdio.h>
#include <string>
#include <iostream>
#define BUFSIZE 4096
#define VARNAME TEXT("tmp")
int main()
{
DWORD dwRetVal;
DWORD dwRet, dwErr;
DWORD dwBufSize=BUFSIZE;
CHAR envtemp[BUFSIZE];
CHAR tempBuffer[BUFSIZE];
CHAR getwindowsBuffer[BUFSIZE];
// Get the temp path.
dwRetVal = GetTempPath(dwBufSize, tempBuffer);
if (dwRetVal > dwBufSize || (dwRetVal == 0))
{
printf ("GetTempPath failed (%d)\n", GetLastError());
}
std::string tpath;
tpath = tempBuffer;
std::cout << tpath << " : Is the Temp Directory path\n";
// Get Windows Directory.
dwRetVal = 0;
dwRetVal = GetWindowsDirectory(getwindowsBuffer, dwBufSize);
if (dwRetVal > dwBufSize || (dwRetVal == 0))
{
printf ("GetWindowsDirectory failed (%d)\n", GetLastError());
}
std::string wpath;
wpath = getwindowsBuffer;
std::cout << wpath << " : Is the Windows Directory path\n";
dwRet = GetEnvironmentVariable(VARNAME, envtemp, BUFSIZE);
if(0 == dwRet)
{
dwErr = GetLastError();
if( ERROR_ENVVAR_NOT_FOUND == dwErr )
{
printf("Environment variable does not exist.\n");
}
else
{
printf("GetEnvironmentVariable failed ( function call not supported )(%d)\n", dwErr);
return FALSE;
}
}
else if(BUFSIZE < dwRet)
{
printf("GetEnvironmentVariable failed (%d)\n", GetLastError());
return FALSE;
}
std::string envpath;
envpath = envtemp;
printf("%s : Is the path for variable %s\n", envtemp, VARNAME);
return (0);
}
Just last question:
Under Windows2000 and above the program above returns the User Temp Directory, but under Windows 98 it returns the Windows Temp Directory!
Could it be that Windows 98 does not have a User Temp Directory or i must use another API function to get it ?