|
i wonder if you did exactly as below
.h
m_pszTimeZones
m_pszTimeZonesNames
.cpp
void <myclassname>::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)
{
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 );
}
}
RegCloseKey(Key);
}
}
}
RegCloseKey( hKey );
}</myclassname>
|
|
|
|
|
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)
{
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");
}
|
|
|
|
|
Hmm, thanks it works. So, it's better to rate your advice to use of CStringArray.
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 <myclass>::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);
}
|
|
|
|
|
Hi Experts,
I want to name of some API to perfome the following tasks:
1.How to Restart the system programatically?
2.API that determines system getting shutdown.
3.API that tells system is starting.
Thanx in advance.
|
|
|
|
|
pther wrote: 1.How to Restart the system programatically?
ExitWindowsEx().
pther wrote: 2.API that determines system getting shutdown.
WM_QUERYENDSESSION
pther wrote: 3.API that tells system is starting.
If the system is in starting state then how can your application be running? Or you want your application to run on startup?
|
|
|
|
|
pther wrote: 1.How to Restart the system programatically?
See ExitWindowsEx
pther wrote: 2.API that determines system getting shutdown.
See WM_QUERYENDSESSION, WM_ENDSESSION messages
pther wrote: 3.API that tells system is starting.
I dont know pal...
|
|
|
|
|
Hi all,
I am trying to create a file by my program on a path specified by user.
I want to verify this path that this path exist or not and is there a file with same name already created....Is there any api which could help me in doing this........
Thanks
|
|
|
|
|
|
|
Use CFileFind class & its member functions
this may help you.
|
|
|
|
|
PathFileExist is the api you have to use for said problem, also you have to include shlwapi.lib in your program!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
You can use of FindFirstFile for check does file exist or no.
|
|
|
|
|
I have craeted a CWinThread object for thread. This thread implements a reccurssive type function. I have used SendMessage/PostMessage functions but it is crashing. Please help me by informing exact reason and alternate solution.
|
|
|
|
|
you will have to be more specific, unless you are expecting some psychic CP member to figure out the 'exact' solution for you...
meanwhile heres a good source on threads that may help you out figure out the problem on your own:
http://www.flounder.com/workerthreads.htm[^]
|
|
|
|
|
What message are you sending?
Could you show me the code fragment?
|
|
|
|
|
I have used the following code in the procedure that run under a thread
ULONG64 ulPercent = INT64(m_ulFileCopied * 100)/INT64(ulFileSize);<br />
SendMessage(UM_PROGRESSS_INFO,(WPARAM)ulPercent,0);
In the above code while executing the SendMessage function the system is crashing. I have also used PostMessage function instead of SendMessage but the result is same.
|
|
|
|
|
I guess it may be due to the invalid window handle. You probably have no window. Try debugging the application. And when the "Abort Retry Ignore" messagebox is displayed, click Retry. Then you can locate the problem by checking call stack.
|
|
|
|
|
AFAIK CWinThread class doesn't provide a PostMessage method, you have to use the global function (supposing hWndMain is the handle of your main window):
::PostMessage(hWndMain, UM_PROGRESSS_INFO,(WPARAM)ulPercent,0);
or the PostThreadMessage method.
BTW sure that crash doesn't depend on recursion?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Md. Ali Naser Khan wrote: ...but it is crashing.
Which means nothing unless you provide some sort of context, supporting information, or at least a code snippet. What exactly does "crash" mean? Is an exception thrown? Is an assertion fired? What does the call stack look like?
"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
|
|
|
|
|
Hi All,,
I know this quetion little much non related to this forum but I found that this is much related to VC++, so I am asking for this problem's suggetion.
I am making Windows Service with help Visual Studio Windows Services Template. And as per my knowledge it uses .Net Framework.I am new at .Net Framework.
My problem is that I want to get user logon- logoff event into my service.So I decided to use LsaEnumerateLogonSessions function.For that I found that I have to use secur32.dll in my application.But how can I include this .DLL into my windows service project.So I don't know how to include this .dll into .Net Framework. Or is there any other way to use this functions into my Service application??
Thanks in Advance.
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|
I found from googled that we can use below staments to include this .dll and to use this function.
<br />
[DllImport ( "Secur32")] <br />
<br />
private static extern int LsaEnumerateLogonSessions(IntPtr LogonSessionCount, IntPtr LogonSessionList); private static extern int LsaEnumerateLogonSessions (IntPtr LogonSessionCount, IntPtr LogonSessionList); <br />
<br />
But I want similler to work with VC++ windows service project.
Plz help me. I have stucked into this problem.
Thanks.
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|
Still not getting reply from your side!!!!!!
Ok let me explore something more that what I have tried that you can understand more in this problem.
I include #include Ntsecapi.h file into my .h file (where I want to use this functions) and I try to use this function like below.but it gives me the errors as I going to show....
<br />
PULONG count;<br />
PLUID *luidptr;<br />
LsaEnumerateLogonSessions(count,luidptr);<br />
I got the errors using this function like below...
<br />
<br />
error LNK2028: unresolved token (0A000009) "extern "C" long __stdcall LsaEnumerateLogonSessions(unsigned long *,struct _LUID * *)" (?LsaEnumerateLogonSessions@@$$J18YGJPAKPAPAU_LUID@@@Z) referenced in function "public: void __clrcall CUserInfo::OnCreate(void)" (?OnCreate@CUserInfo@@$$FQ$AAMXXZ)<br />
<br />
error LNK2019: unresolved external symbol "extern "C" long __stdcall LsaEnumerateLogonSessions(unsigned long *,struct _LUID * *)" (?LsaEnumerateLogonSessions@@$$J18YGJPAKPAPAU_LUID@@@Z) referenced in function "public: void __clrcall CUserInfo::OnCreate(void)" (?OnCreate@CUserInfo@@$$FQ$AAMXXZ)<br />
<br />
fatal error LNK1120: 2 unresolved externals<br />
Plz help me. I am confused with problem.
Ashish Bhatt,
System Developer,
Avinashi System Pvt. Ltd.
|
|
|
|
|