|
U can use GetLocalTime () . This API is very easier to use.
Come online at:-
jubinc@skype
|
|
|
|
|
Thanks Don , I will make use of it .
|
|
|
|
|
SYSTEMTime is for use with GetSystemTime() function.
Example :
1.
SYSTEMTIME stSystime;
GetSystemTime(&stSystime);
This will load UTC time into stSystime variable.
2.
SYSTEMTIME stSystime;
GetLocalTime(&stSystime);
3. Your Code with Local time Logging:
outf.open("C:\\Log.txt",ios::app);
SYSTEMTIME st;
// Add this line
GetLocalTime(&stSystime);
//Remove this line
//::SendMessage(hwnd, DTM_GETSYSTEMTIME, 0, (LPARAM)&st);
LPTSTR lpDateTime = new TCHAR[21];
_stprintf(lpDateTime, _T("%02u/%02u/%04u %2u:%2u:%2u"),
st.wMonth, st.wDay, st.wYear,st.wHour, st.wMinute, st.wSecond);
outf << "Current selected time: " << lpDateTime;
delete []lpDateTime;
outf.close();
|
|
|
|
|
Thanks Babu,
Your code is working … I made changes to my code its working as expected.
Thank you very much ….
|
|
|
|
|
Suresh H wrote: _stprintf(lpDateTime, _T("%02u/%02u/%04u %2u:%2u:%2u"),
st.wMonth, st.wDay, st.wYear,st.wHour, st.wMinute, st.wSecond);
Why not put a breakpoint on this statement to verify the values of st before bothering to write them to the file?
The "crash" is happening because you are writing 36 bytes into a buffer that can only hold 21.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi David,
Thank you very much for the explaining the cause of crash.
I had actually used break points to check the crash , I found it was cashing at this statement delete []lpDateTime; and also I was not getting the proper out put I had commented the delete statement and I was concentrating on the GetLocalTime function once I got the proper time and date later I checked the cause and I found that I had used 21 bytes instead of 36 bytes.
Now I got the solution for the crash.
Thanking you.,
Suresh HC
|
|
|
|
|
Suresh H wrote: I found it was cashing at this statement delete []lpDateTime;
And rightly so since lpDateTime had been stepped all over. The array is indeed large enough; you just need to verify that you're not trying to stuff too much into it.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
need a win32 api that authenticates a windows NT user or the like... pl post any links for the same.. thanks..
|
|
|
|
|
|
I have a code as follows:
class __declspec ( dllexport ) CCASObject : public CObject
{
public:
virtual void operator=( const CCADSObject& )
{}
};
class CSpanLoad : public CCASObject
{
public:
void operator=( const CCASObject& );
};
//spanload.cpp
void CSpanLoad::operator=( const CCASObject &src )
{
//....
}
//Import.cpp
int CImport::ReadLoadCategoryData()
{
CSpanLoad *pA3Ld,*pBDLd;
*pA3Ld = *pBDLd; //this assignment is giving error in
VS2005.In VC6 it was not showing the error;
}
ERROR is:
error C2248: 'CObject::operator =' : cannot access private member declared in class 'CObject'"
see declaration of 'CObject::operator ='
see declaration of 'CObject'
This diagnostic occurred in the compiler generated function 'CPtrArray &CPtrArray::operator =(const CPtrArray &)'
Why the error after .net conversiom?
Plz help..
Thanks and Regards
|
|
|
|
|
Hi All,
I've been having a run of it lately. Below, the Mapped File Address is good (pcbNTFileHeader = 0x00310000), and the offset is good (offset=232 or 0xE8). Ultimately, I should arrive at 0x003100E8.
But the compiler is generating an imul instruction... which is creating an address of 0x0031E0C0 (0xE0C0 is 0xF8*232). Any ideas?
Jeff
<PRE> pcbNTFileHeader = static_cast< PIMAGE_NT_HEADERS >( pcbMappedFile );
0043481D mov eax,dword ptr [pcbMappedFile]
00434820 mov dword ptr [pcbNTFileHeader],eax
SIZE_T offset = pcbDOSHeader->e_lfanew;
00434826 mov eax,dword ptr [pcbDOSHeader]
00434829 mov ecx,dword ptr [eax+3Ch]
0043482C mov dword ptr [offset],ecx
pcbNTFileHeader += offset;
00434832 mov eax,dword ptr [offset]
00434838 imul eax,eax,0F8h
0043483E mov ecx,dword ptr [pcbNTFileHeader]
00434844 add ecx,eax
00434846 mov dword ptr [pcbNTFileHeader],ecx</PRE>
The full program is below.
<PRE>// CodeDump.cpp
int _tmain( )
{
TCHAR pszFilename[] = _T("C:\\HelloWorld.exe");
HANDLE hFile = NULL;
HANDLE hFileMapping = NULL;
PVOID pcbMappedFile = NULL;
PIMAGE_DOS_HEADER pcbDOSHeader = NULL;
PIMAGE_FILE_HEADER pcbFileHeader = NULL;
PIMAGE_NT_HEADERS pcbNTFileHeader = NULL;
__try {
hFile = CreateFile( pszFilename, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if ( hFile == INVALID_HANDLE_VALUE )
{
std::tcout << _T("Error - CreateFile()") << std::endl;
__leave;
}
hFileMapping = CreateFileMapping(hFile, NULL,
PAGE_READONLY, 0, 0, NULL);
if ( NULL == hFileMapping )
{
std::tcout << _T("Error - CreateFileMapping()") << std::endl;
__leave;
}
pcbMappedFile = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
if ( NULL == pcbMappedFile )
{
std::tcout << _T("Error - MapViewOfFile()") << std::endl;
__leave;
}
pcbDOSHeader = static_cast<PIMAGE_DOS_HEADER>( pcbMappedFile );
if( pcbDOSHeader->e_magic != IMAGE_DOS_SIGNATURE )
{
std::tcout << _T("Error - File is not EXE Format") << std::endl;
__leave;
}
pcbNTFileHeader = static_cast< PIMAGE_NT_HEADERS >( pcbMappedFile );
SIZE_T offset = pcbDOSHeader->e_lfanew;
pcbNTFileHeader += offset;
if( pcbNTFileHeader->Signature != IMAGE_NT_SIGNATURE )
{
std::tcout << _T("Error - File is not PE Format") << std::endl;
__leave;
}
} // __try
__except( EXCEPTION_EXECUTE_HANDLER ) {
std::tcout << _T("Caught Exception") << std::endl;
}
if( NULL != hFile ) { CloseHandle( hFile ); }
if( NULL != hFileMapping ) { CloseHandle( hFileMapping ); }
return 0;
}</PRE>
|
|
|
|
|
Can you alter your code such that the types you're casting to are visible. i.e. I can't see the "<"'s or the ">"'s or the types between in your code. Use HTML entities or the buttons below the post window.
Steve
|
|
|
|
|
Hi Stephen,
Stephen Hewitt wrote: I can't see the "<"'s
Very annoying (I though I got it). The damned thing about it, the pretty printer or formatter will go in and touch code labelled <PRE>, putting those obnoxious smiley faces in, but won't fix a greater than or less than sign.
Jeff
|
|
|
|
|
Don't mean to insult you, but you realize offset is number of headers, not number of bytes right.
That's why the imul is there, to convert offset from header count (offset) to bytes.
If pcbNTFileHeader was a byte pointer then offset would need to be in bytes.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi cmk,
cmk wrote: Don't mean to insult you
Not usually possible - I don't really have an ego...
cmk wrote: ... offset is number of headers, not number of bytes right
Not quite yet: offset is number bytes into the Mapping I need to be. Basically, it steps over the DOS stub. Once I successfully get to IMAGE_NT_HEADERS, the next casts to an IMAGE_FILE_HEADER and IMAGE_OPTIONAL_HEADER will give me the number of segments - if I can get my math right.
Jeff
|
|
|
|
|
Don't do this:
pcbNTFileHeader += offset;
As another poster mentioned, this skips over 'offset' file headers not 'offset' bytes. Instead do something like this:
pcbNTFileHeader = (PIMAGE_NT_HEADERS)((ULONG_PTR)pcbNTFileHeader+offset);
I normally would not use C-style casts but sometimes I make an exception in low-level code such as this.
Steve
|
|
|
|
|
Hi Steve,
That was it - I did not want to cast away the PVOID on the File Mapping before adding the offset, but the compiler was complaining about the math...
Jeff
pNTHeader = reinterpret_cast< PIMAGE_NT_HEADERS >(
(PBYTE)pcbMappedFile + pDOSHeader->e_lfanew );
if( pNTHeader->Signature != IMAGE_NT_SIGNATURE )
{
std::cout << _T("Error - File is not PE Format") << std::endl;
__leave;
}
|
|
|
|
|
Is there a c++ equivalent of vbs's DateAdd where you can add or subtract any amount of hours, days, months etc. to a date?
- thanks
|
|
|
|
|
If you are using MFC, see the COleDateTime class.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: If you are using MFC, see the COleDateTime class.
Nope, pure Win32
|
|
|
|
|
Ok. How are you obtaining the date value you want to manipulate?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
GetSystemTime() (then converting it to local time).
|
|
|
|
|
So do you have a SYSTEMTIME or a FILETIME object at this point?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
SYSTEMTIME.
SYSTEMTIME stDateIWantToAddDaysOrMonthsTo;
FILETIME ft, ftLocal;
GetSystemTimeAsFileTime(&ft);
FileTimeToLocalFileTime(&ft, &ftLocal);
FileTimeToSystemTime(&ftLocal, &stDateIWantToAddDaysOrMonthsTo);
|
|
|
|