|
|
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);
|
|
|
|
|
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
|
|
|
|