|
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);
|
|
|
|
|
Ok, so what problem(s) are you having with "add or subtract any amount of hours, days, months etc. to a date?"
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I don't know of any function that does this. I was looking for something like VBScript's DateAdd where I could do something like DateAdd(Month, 24, &stMyDate) and it would add 24 months to the date (2 years), taking into account leap years etc..
|
|
|
|
|
nm_114 wrote: I don't know of any function that does this.
Why would you need a function, when one statement will work:
stDateIWantToAddDaysOrMonthsTo.wYear += 2; You could roll your own function to this I suppose. Take a stroll through the other date/time functions to see what is available to you.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Why would you need a function, when one statement will work:
It was a bad example I guess. It needs to be arbitrary. Like DateAdd(Month, 309, mydate) , DateAdd(Day, -909, mydate) etc. I'm not sure if I'm explaining it right.
DavidCrow wrote: Take a stroll through the other date/time functions to see what is available to you.
I did. I didn't see anything like DateAdd.
|
|
|
|
|
If you convert the SYSTEMTIME structure to a FILETIME structure, you can add/subtract such values.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
nm_114 wrote: How?
By using SystemTimeToFileTime() .
nm_114 wrote: I found an article at
http://www.codeproject.com/datetime/winapi_datetime_ops.asp[^]
That article is exactly what you need.
nm_114 wrote:
but it doesn't work with months/years
That's because a month does not have a constant value (i.e., 28, 29, 30, or 31 days) like the other items do.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: nm_114 wrote:
How?
By using SystemTimeToFileTime().
Well I knew that much! I was asking how you do the adding/subtracting...
DavidCrow wrote: That article is exactly what you need.
Well not really, as it doesn't handle months/years.
DavidCrow wrote: That's because a month does not have a constant value (i.e., 28, 29, 30, or 31 days) like the other items do.
I knew that too! But it's ok, I guess what I was looking for doesn't exist (a tested/bug-free exact replica of DateAdd() in C++). Oh well .
Thanks anyway.
|
|
|
|
|
nm_114 wrote: Well not really, as it doesn't handle months/years.
I already showed you how to add months to the SYSTEMTIME object. You would add years in the same fashion. What you have to account for when adding months is to make sure to increment years accordingly. For example, if it's September and you want to add four months, you would use:
wMonth = (wMonth + 4) % 12; But you would then have to add one to the year.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Yep. I guess I was hesitant to write my own because I don't know how to account for leap years, but I guess it's not critical. I'll probably use that other article and write something similar to your example for months/years.
Thanks.
|
|
|
|
|
nm_114 wrote: ...I don't know how to account for leap years...
Are you kidding? Leap year algorithms/functions are plentiful here at CP, or even Googling for them.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
See if it helps you ...
int nDay;
int nMonth;
int nYear;
struct tm *when;
time_t now, result;
time( &now );
when = localtime( &now );//conversion from UTC to system time
if(when == NULL)//Error in the calculation of time
return -1;
when->tm_mday = when->tm_mday + nDays;
result = mktime( when );
if(result == (time_t)-1)//size of time_t = 0;result=-1--->error in calculation of result
{
return -1;
}
else
{
nDay = when->tm_mday;
nMonth = when->tm_mon+1;
nYear = when->tm_year+1900;
}
impossible to understand
|
|
|
|
|
Hi All,
I'm prototyping code, and can't seem to persist a hexadecimal base. The following does not perform as expected (it still outputs base 10):
std::cout.unsetf ( std::ios_base::dec );<br />
std::cout.setf ( std::ios_base::hex );<br />
std::cout.setf ( std::ios_base::uppercase );
The alternative (which I am now trying to avoid) is:
std::cout << std::hex << 0x1000 << std::endl;
Any ideas? I'm not sure if I am not using the stream correctly, missing a Microsoft feature, or making an incorrect assumption for flag manipulation.
Thanks,
Jeff
|
|
|
|