How to use GetTimeZoneInformation
-
One step more done. Read the registry as follows.
HKEY hKey;// Handle to the registry DWORD dwType = REG\_SZ;// Data type char buf\[255\];// Data DWORD dwBufSize = sizeof(buf); // Sub handle to the registry const char\* subKey = "SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Time Zones\\\\Afghanistan Standard Time"; // Open the handler if(RegOpenKey(HKEY\_LOCAL\_MACHINE, subKey, &hKey) == ERROR\_SUCCESS) { // Do the processing, find the name if(RegQueryValueEx(hKey, "Display", 0, &dwType, (BYTE\*)buf, &dwBufSize) == ERROR\_SUCCESS) { AfxMessageBox(buf); } else { AfxMessageBox("Error in reading values.", MB\_OK); } // Close the handler RegCloseKey(hKey); } else { AfxMessageBox("Error in reading registry.", MB\_OK); }
As you can see, this code gives the values related to the Afghanistan Standard Time. I want to iterate through the list of Time Zones. In this way each time zone I can compare the user time offset with register values.
I appreciate your help all the time... Eranga :)
Eranga Thennakoon wrote:
I want to iterate through the list of Time Zones.
So why not use
RegEnumValue()
?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Eranga Thennakoon wrote:
I want to iterate through the list of Time Zones.
So why not use
RegEnumValue()
?"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
I do the enumerating as follows. How can I avoid the multiple findings. I mean, say there is more than one time zone for same time offset. In that case I want to display the very first time zone name. Used a break statement as follows. For some offsets it doesn't work.
for (i=0; i < cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
// Enumerate subkeys of Time Zones
retCode = RegEnumKeyEx(hKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime);// Make the new path for the registry char newPath\[255\]; sprintf(newPath, "%s\\\\%s", path, achKey); printf("\\n%s", newPath); // Work with the second handler if(RegOpenKey(HKEY\_LOCAL\_MACHINE, newPath, &hSubKey) == ERROR\_SUCCESS) { if(RegQueryValueEx(hSubKey, "Display", 0, &dwType, (BYTE\*)buf, &dwBufSize) == ERROR\_SUCCESS) { string strDisplay(buf);// Display name string strSub = strDisplay.substr(4, 6); // String comparing int result; result = strcmp(strSub.c\_str(), str.c\_str()); if(result == 0) { printf("\\n%s", strDisplay.c\_str());// Time offset break; } } RegCloseKey(hSubKey); } else { printf("\\nNo "); } }
I appreciate your help all the time... Eranga :)
-
I do the enumerating as follows. How can I avoid the multiple findings. I mean, say there is more than one time zone for same time offset. In that case I want to display the very first time zone name. Used a break statement as follows. For some offsets it doesn't work.
for (i=0; i < cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
// Enumerate subkeys of Time Zones
retCode = RegEnumKeyEx(hKey, i, achKey, &cbName, NULL, NULL, NULL, &ftLastWriteTime);// Make the new path for the registry char newPath\[255\]; sprintf(newPath, "%s\\\\%s", path, achKey); printf("\\n%s", newPath); // Work with the second handler if(RegOpenKey(HKEY\_LOCAL\_MACHINE, newPath, &hSubKey) == ERROR\_SUCCESS) { if(RegQueryValueEx(hSubKey, "Display", 0, &dwType, (BYTE\*)buf, &dwBufSize) == ERROR\_SUCCESS) { string strDisplay(buf);// Display name string strSub = strDisplay.substr(4, 6); // String comparing int result; result = strcmp(strSub.c\_str(), str.c\_str()); if(result == 0) { printf("\\n%s", strDisplay.c\_str());// Time offset break; } } RegCloseKey(hSubKey); } else { printf("\\nNo "); } }
I appreciate your help all the time... Eranga :)
-
for -09:00 it wont work. i'm expecting it for Alaskan Standard Time time zone. That is the second subkey of the Time Zones key of the registry. My code don't recognized it at all.
I appreciate your help all the time... Eranga :)
-
for -09:00 it wont work. i'm expecting it for Alaskan Standard Time time zone. That is the second subkey of the Time Zones key of the registry. My code don't recognized it at all.
I appreciate your help all the time... Eranga :)
i will use something like this: i will store all zones into m_pszTimeZones and after that it is easy to get information you want .h CStringArray m_pszTimeZones; .cpp void ::TestTM { HKEY hKey, Key; DWORD dwType = REG_SZ; int iRet = 0; CString strName, strValue, strPath, strKey; strPath = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strPath, 0, KEY_READ, &hKey); if (iRet != ERROR_SUCCESS) return; TCHAR achKey[MAX_PATH]; TCHAR achClass[MAX_PATH] = _T(""); DWORD cchClassName = MAX_PATH; DWORD cSubKeys; DWORD cbMaxSubKey; DWORD cchMaxClass; DWORD cValues; DWORD cchMaxValue; DWORD cbMaxValueData; DWORD cbSecurityDescriptor; FILETIME ftLastWriteTime; DWORD i; DWORD retCode; TCHAR buffer[MAX_PATH]; DWORD dwSize = sizeof(buffer); // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // Enumerate the child keys, until RegEnumKeyEx fails. Then // get the name of each child key and copy it into the list box. for (i = 0, retCode = ERROR_SUCCESS;retCode == ERROR_SUCCESS; i++) { ZeroMemory(&achKey, sizeof(achKey)); cbMaxSubKey = sizeof(achKey); retCode = RegEnumKeyEx(hKey, i, achKey, &cbMaxSubKey, NULL, NULL, NULL, &ftLastWriteTime); if (retCode == (DWORD)ERROR_SUCCESS) { strName.Format( _T("%s"), achKey); strKey = strPath + "\\" + strName; iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_READ, &Key); if (iRet == ERROR_SUCCESS) { ZeroMemory(&buffer, sizeof(buffer)); dwSize = sizeof(buffer); //again iRet = RegQueryValueEx(Key, _T("Display"), NULL, &dwType, (BYTE *)buffer, &dwSize);
-
i will use something like this: i will store all zones into m_pszTimeZones and after that it is easy to get information you want .h CStringArray m_pszTimeZones; .cpp void ::TestTM { HKEY hKey, Key; DWORD dwType = REG_SZ; int iRet = 0; CString strName, strValue, strPath, strKey; strPath = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strPath, 0, KEY_READ, &hKey); if (iRet != ERROR_SUCCESS) return; TCHAR achKey[MAX_PATH]; TCHAR achClass[MAX_PATH] = _T(""); DWORD cchClassName = MAX_PATH; DWORD cSubKeys; DWORD cbMaxSubKey; DWORD cchMaxClass; DWORD cValues; DWORD cchMaxValue; DWORD cbMaxValueData; DWORD cbSecurityDescriptor; FILETIME ftLastWriteTime; DWORD i; DWORD retCode; TCHAR buffer[MAX_PATH]; DWORD dwSize = sizeof(buffer); // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // Enumerate the child keys, until RegEnumKeyEx fails. Then // get the name of each child key and copy it into the list box. for (i = 0, retCode = ERROR_SUCCESS;retCode == ERROR_SUCCESS; i++) { ZeroMemory(&achKey, sizeof(achKey)); cbMaxSubKey = sizeof(achKey); retCode = RegEnumKeyEx(hKey, i, achKey, &cbMaxSubKey, NULL, NULL, NULL, &ftLastWriteTime); if (retCode == (DWORD)ERROR_SUCCESS) { strName.Format( _T("%s"), achKey); strKey = strPath + "\\" + strName; iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_READ, &Key); if (iRet == ERROR_SUCCESS) { ZeroMemory(&buffer, sizeof(buffer)); dwSize = sizeof(buffer); //again iRet = RegQueryValueEx(Key, _T("Display"), NULL, &dwType, (BYTE *)buffer, &dwSize);
Then do the comparing with user inputs?
I appreciate your help all the time... Eranga :)
-
Then do the comparing with user inputs?
I appreciate your help all the time... Eranga :)
-
yes... like where strInput = "-09:00" CString strTest; int i; for(i=0;i<=m_pszTimeZones.GetUpperBound();i++) { strTest = m_pszTimeZones.GetAt(i); strTest = strTest.Mid(4,6); if ( strTest == strInput) break; }
Ok, thanks. I'll check it and let you know.
I appreciate your help all the time... Eranga :)
-
yes... like where strInput = "-09:00" CString strTest; int i; for(i=0;i<=m_pszTimeZones.GetUpperBound();i++) { strTest = m_pszTimeZones.GetAt(i); strTest = strTest.Mid(4,6); if ( strTest == strInput) break; }
Hey dan o, your code works fine. Where I'm going wrong is the use of my buffer. I'm not sure what exactly happened, but the changing of the buffer size for different time zones gives an error. Thanks buddy, At the same time, I'm try to do another thing. Say I want to get both display name and standard zone name. How can I do that through the above your code.
I appreciate your help all the time... Eranga :)
-
Hey dan o, your code works fine. Where I'm going wrong is the use of my buffer. I'm not sure what exactly happened, but the changing of the buffer size for different time zones gives an error. Thanks buddy, At the same time, I'm try to do another thing. Say I want to get both display name and standard zone name. How can I do that through the above your code.
I appreciate your help all the time... Eranga :)
ok, anyway just closing this item now... just make a new stringarray CStringArray m_pszTimeZonesNames if (iRet == ERROR_SUCCESS) { ZeroMemory(&buffer, sizeof(buffer)); dwSize = sizeof(buffer); //again iRet = RegQueryValueEx(Key, _T("Std"), NULL, &dwType, (BYTE *)buffer, &dwSize); if (iRet == ERROR_SUCCESS) { strValue.Format(_T("%s"), buffer); m_pszTimeZonesNames.Add( strValue ); } have a nice day
-
ok, anyway just closing this item now... just make a new stringarray CStringArray m_pszTimeZonesNames if (iRet == ERROR_SUCCESS) { ZeroMemory(&buffer, sizeof(buffer)); dwSize = sizeof(buffer); //again iRet = RegQueryValueEx(Key, _T("Std"), NULL, &dwType, (BYTE *)buffer, &dwSize); if (iRet == ERROR_SUCCESS) { strValue.Format(_T("%s"), buffer); m_pszTimeZonesNames.Add( strValue ); } have a nice day
That's what I have tried. But when I add a CStringArray and compile its ok, but I can't run the code. When I run following exception given,
Unhandled exception at 0x00414ff3 in TimeZone.exe: 0xC0000005: Access violation writing location 0x00000020.
on following line of code.
m_pMainWnd = &dlg;
I have no idea about that. Even on CStringArray documentation there is no such explanation.
I appreciate your help all the time... Eranga :)
-
That's what I have tried. But when I add a CStringArray and compile its ok, but I can't run the code. When I run following exception given,
Unhandled exception at 0x00414ff3 in TimeZone.exe: 0xC0000005: Access violation writing location 0x00000020.
on following line of code.
m_pMainWnd = &dlg;
I have no idea about that. Even on CStringArray documentation there is no such explanation.
I appreciate your help all the time... Eranga :)
i wonder if you did exactly as below .h m_pszTimeZones m_pszTimeZonesNames .cpp void ::TestTZ() { HKEY hKey, Key; DWORD dwType = REG_SZ; int iRet = 0; CString strName, strValue, strPath, strKey; strPath = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strPath, 0, KEY_READ, &hKey); if (iRet != ERROR_SUCCESS) return; TCHAR achKey[MAX_PATH]; TCHAR achClass[MAX_PATH] = _T(""); DWORD cchClassName = MAX_PATH; DWORD cSubKeys; DWORD cbMaxSubKey; DWORD cchMaxClass; DWORD cValues; DWORD cchMaxValue; DWORD cbMaxValueData; DWORD cbSecurityDescriptor; FILETIME ftLastWriteTime; DWORD i; DWORD retCode; TCHAR buffer[MAX_PATH]; DWORD dwSize = sizeof(buffer); // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // Enumerate the child keys, until RegEnumKeyEx fails. Then // get the name of each child key and copy it into the list box. for (i = 0, retCode = ERROR_SUCCESS;retCode == ERROR_SUCCESS; i++) { ZeroMemory(&achKey, sizeof(achKey)); cbMaxSubKey = sizeof(achKey); retCode = RegEnumKeyEx(hKey, i, achKey, &cbMaxSubKey, NULL, NULL, NULL, &ftLastWriteTime); if (retCode == (DWORD)ERROR_SUCCESS) { strName.Format( _T("%s"), achKey); strKey = strPath + "\\" + strName; iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_READ, &Key); if (iRet == ERROR_SUCCESS) { ZeroMemory(&buffer, sizeof(buffer)); dwSize = sizeof(buffer); //again iRet = RegQueryValueEx(Key, _T("Display"), NULL, &dwType, (BYTE *)buffer, &dwSize); if (iRet == ERROR_SUCCESS) { strValue.Format(_T("%s"), buffer); m_pszTimeZones.Add( strValue ); } if (iRet == ERROR_SUCCESS)
-
i wonder if you did exactly as below .h m_pszTimeZones m_pszTimeZonesNames .cpp void ::TestTZ() { HKEY hKey, Key; DWORD dwType = REG_SZ; int iRet = 0; CString strName, strValue, strPath, strKey; strPath = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strPath, 0, KEY_READ, &hKey); if (iRet != ERROR_SUCCESS) return; TCHAR achKey[MAX_PATH]; TCHAR achClass[MAX_PATH] = _T(""); DWORD cchClassName = MAX_PATH; DWORD cSubKeys; DWORD cbMaxSubKey; DWORD cchMaxClass; DWORD cValues; DWORD cchMaxValue; DWORD cbMaxValueData; DWORD cbSecurityDescriptor; FILETIME ftLastWriteTime; DWORD i; DWORD retCode; TCHAR buffer[MAX_PATH]; DWORD dwSize = sizeof(buffer); // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // Enumerate the child keys, until RegEnumKeyEx fails. Then // get the name of each child key and copy it into the list box. for (i = 0, retCode = ERROR_SUCCESS;retCode == ERROR_SUCCESS; i++) { ZeroMemory(&achKey, sizeof(achKey)); cbMaxSubKey = sizeof(achKey); retCode = RegEnumKeyEx(hKey, i, achKey, &cbMaxSubKey, NULL, NULL, NULL, &ftLastWriteTime); if (retCode == (DWORD)ERROR_SUCCESS) { strName.Format( _T("%s"), achKey); strKey = strPath + "\\" + strName; iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_READ, &Key); if (iRet == ERROR_SUCCESS) { ZeroMemory(&buffer, sizeof(buffer)); dwSize = sizeof(buffer); //again iRet = RegQueryValueEx(Key, _T("Display"), NULL, &dwType, (BYTE *)buffer, &dwSize); if (iRet == ERROR_SUCCESS) { strValue.Format(_T("%s"), buffer); m_pszTimeZones.Add( strValue ); } if (iRet == ERROR_SUCCESS)
Oops, it's work. I have to clear the array after certain time I think. Do this after some time of use the array.
m_pszTimeZones.RemoveAll();
Now seems it is work. Another thing also tested by me. On comparing of user input with array element, if the user input is not found what happened.
for(i=0;i<=m\_pszTimeZones.GetUpperBound();i++) { strTest = m\_pszTimeZones.GetAt(i); strTemp = m\_pszTimeZones.GetAt(i); stdTT = m\_pszNames.GetAt(i); strTest = strTest.Mid(4,6); if ( strTest == strIn) { // Here find the correct zone name SetDetails(strTemp); SetDlgItemText(IDC\_STD, stdTT); break; } else { AfxMessageBox("Error"); break; } }
This is what I have tried. Because of the second break it wont iterate. If removed the second break, get the error message until it is found. How should I avoid it.
I appreciate your help all the time... Eranga :)
-
Oops, it's work. I have to clear the array after certain time I think. Do this after some time of use the array.
m_pszTimeZones.RemoveAll();
Now seems it is work. Another thing also tested by me. On comparing of user input with array element, if the user input is not found what happened.
for(i=0;i<=m\_pszTimeZones.GetUpperBound();i++) { strTest = m\_pszTimeZones.GetAt(i); strTemp = m\_pszTimeZones.GetAt(i); stdTT = m\_pszNames.GetAt(i); strTest = strTest.Mid(4,6); if ( strTest == strIn) { // Here find the correct zone name SetDetails(strTemp); SetDlgItemText(IDC\_STD, stdTT); break; } else { AfxMessageBox("Error"); break; } }
This is what I have tried. Because of the second break it wont iterate. If removed the second break, get the error message until it is found. How should I avoid it.
I appreciate your help all the time... Eranga :)
BOOL bFound = FALSE; for(i=0;i<=m_pszTimeZones.GetUpperBound();i++) { strTest = m_pszTimeZones.GetAt(i); strTemp = m_pszTimeZones.GetAt(i); stdTT = m_pszNames.GetAt(i); strTest = strTest.Mid(4,6); if ( strTest == strIn) { // Here find the correct zone name SetDetails(strTemp); SetDlgItemText(IDC_STD, stdTT); bFound = TRUE; break; } } if (!bFound) { AfxMessageBox("Error, No Found"); }
-
BOOL bFound = FALSE; for(i=0;i<=m_pszTimeZones.GetUpperBound();i++) { strTest = m_pszTimeZones.GetAt(i); strTemp = m_pszTimeZones.GetAt(i); stdTT = m_pszNames.GetAt(i); strTest = strTest.Mid(4,6); if ( strTest == strIn) { // Here find the correct zone name SetDetails(strTemp); SetDlgItemText(IDC_STD, stdTT); bFound = TRUE; break; } } if (!bFound) { AfxMessageBox("Error, No Found"); }
Hmm, thanks it works. So, it's better to rate your advice to use of CStringArray. :)
I appreciate your help all the time... Eranga :)
-
i will use something like this: i will store all zones into m_pszTimeZones and after that it is easy to get information you want .h CStringArray m_pszTimeZones; .cpp void ::TestTM { HKEY hKey, Key; DWORD dwType = REG_SZ; int iRet = 0; CString strName, strValue, strPath, strKey; strPath = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strPath, 0, KEY_READ, &hKey); if (iRet != ERROR_SUCCESS) return; TCHAR achKey[MAX_PATH]; TCHAR achClass[MAX_PATH] = _T(""); DWORD cchClassName = MAX_PATH; DWORD cSubKeys; DWORD cbMaxSubKey; DWORD cchMaxClass; DWORD cValues; DWORD cchMaxValue; DWORD cbMaxValueData; DWORD cbSecurityDescriptor; FILETIME ftLastWriteTime; DWORD i; DWORD retCode; TCHAR buffer[MAX_PATH]; DWORD dwSize = sizeof(buffer); // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // Enumerate the child keys, until RegEnumKeyEx fails. Then // get the name of each child key and copy it into the list box. for (i = 0, retCode = ERROR_SUCCESS;retCode == ERROR_SUCCESS; i++) { ZeroMemory(&achKey, sizeof(achKey)); cbMaxSubKey = sizeof(achKey); retCode = RegEnumKeyEx(hKey, i, achKey, &cbMaxSubKey, NULL, NULL, NULL, &ftLastWriteTime); if (retCode == (DWORD)ERROR_SUCCESS) { strName.Format( _T("%s"), achKey); strKey = strPath + "\\" + strName; iRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKey, 0, KEY_READ, &Key); if (iRet == ERROR_SUCCESS) { ZeroMemory(&buffer, sizeof(buffer)); dwSize = sizeof(buffer); //again iRet = RegQueryValueEx(Key, _T("Display"), NULL, &dwType, (BYTE *)buffer, &dwSize);
Hi all, After completing the time zone application now I'm going to workout a similar application. Say I have a folder which contain large number of files. I want to read that folder and collect some information on those files. In details view of a folder we can see that lots of details are available. eg: File Name, Size, Date Created, Date Modified and many more. I want to read a specific folder and collect those details. So from where I should start this work.
I appreciate your help all the time... Eranga :)
-
Hi all, After completing the time zone application now I'm going to workout a similar application. Say I have a folder which contain large number of files. I want to read that folder and collect some information on those files. In details view of a folder we can see that lots of details are available. eg: File Name, Size, Date Created, Date Modified and many more. I want to read a specific folder and collect those details. So from where I should start this work.
I appreciate your help all the time... Eranga :)
perhaps next code snippet helps you CStringArray m_pszFileNames void ::TestFile() { struct _finddata_t g_file; long hFile, lTime; CString strName, strPath, strCurrentPath; m_pszFileNames.RemoveAll(); strPath = "c:\testpath"; /* Get the current working directory: */ char buffer[_MAX_PATH]; _getcwd( buffer, _MAX_PATH ); strCurrentPath.Format( _T("%s"), buffer); _tchdir(strPath); if( (hFile = _findfirst( "*.*", &g_file )) == -1L ) { printf( "No files in current directory!\n" ); } else { strName = g_file.name; m_pszFileNames.Add(strName); /* Find the rest of the *.* files */ while( _findnext( hFile, &g_file ) == 0 ) { strName = g_file.name; m_pszFileNames.Add(strName); lTime = g_file.time_write; } _findclose( hFile ); } _tchdir(strCurrentPath); }