Click here to Skip to main content
15,913,198 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Error with CArray, CMap Pin
Jijo.Raj30-May-08 5:52
Jijo.Raj30-May-08 5:52 
GeneralRe: Error with CArray, CMap Pin
Trupti Mehta30-May-08 22:41
Trupti Mehta30-May-08 22:41 
GeneralRe: Error with CArray, CMap Pin
Jijo.Raj30-May-08 23:16
Jijo.Raj30-May-08 23:16 
GeneralRe: Error with CArray, CMap Pin
Trupti Mehta31-May-08 0:38
Trupti Mehta31-May-08 0:38 
GeneralRe: Error with CArray, CMap Pin
Jijo.Raj31-May-08 6:28
Jijo.Raj31-May-08 6:28 
GeneralRe: Error with CArray, CMap Pin
Trupti Mehta1-Jun-08 0:05
Trupti Mehta1-Jun-08 0:05 
GeneralRe: Error with CArray, CMap Pin
Jijo.Raj1-Jun-08 1:59
Jijo.Raj1-Jun-08 1:59 
GeneralRe: Error with CArray, CMap Pin
Trupti Mehta1-Jun-08 8:57
Trupti Mehta1-Jun-08 8:57 
class DeptDetails : public CObject
{
	DECLARE_SERIAL(DeptDetails);

public:
	DeptDetails(void);
	DeptDetails(int dno, CString name, float vat);
	DeptDetails(const DeptDetails &d);	// Copy Constructor
	// = Assignment operator
	DeptDetails& operator=(const DeptDetails &d);


IMPLEMENT_SERIAL(DeptDetails, CObject, 1);

DeptDetails::DeptDetails(void)
: deptNo(0)
, deptName(_T(""))
, vat(0)
{
}

DeptDetails::DeptDetails(int dno, CString name, float vat) {
	deptNo = dno;
	deptName = name;
	this->vat = vat;
}

// Copy Constructor
DeptDetails::DeptDetails(const DeptDetails &d) {
	deptNo = d.deptNo;
	deptName = d.deptName;
	vat = d.vat;
}

// Assignment operator
DeptDetails& DeptDetails::operator=(const DeptDetails &d) {
	deptNo = d.deptNo;
	deptName = d.deptName;
	vat = d.vat;
	
	return *this;
}


class DbOperations  
{
public:
	CMap<int, int, DeptDetails, DeptDetails> deptMap; // = new CMapStringToOb;
	void WriteOperators(CMap<int, int, OperatorDetails, OperatorDetails> opdtMap);


void DbOperations::WriteDepartments(CMap<int, int, DeptDetails, DeptDetails> dptMap)
{
	HANDLE hFile = CreateFile(DEPT_FILE,
	     GENERIC_WRITE, FILE_SHARE_WRITE,
         NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	if (hFile == INVALID_HANDLE_VALUE)
		AfxMessageBox(_T("Error OPeniong File"));
	else {
		CFile myfile((int)hFile);
		int key;
		DeptDetails dd;

		CArchive ar(&myfile, CArchive::store);

		for (POSITION pos = dptMap.GetStartPosition(); pos != NULL;) {
			dptMap.GetNextAssoc(pos, key, dd ); 
			ar.WriteObject(&dd);
		//	dd.Serialize(ar);		
		}
		
		dd.~DeptDetails();
		ar.Close();
		myfile.Close();
	}

	return;
}

CMap<int, int, DeptDetails, DeptDetails> DbOperations::ReadDepartments()
{
	if(deptMap.IsEmpty() == false)
		deptMap.RemoveAll();

	HANDLE hFile = CreateFile(DEPT_FILE,
	     GENERIC_READ, FILE_SHARE_READ,
         NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	if (hFile == INVALID_HANDLE_VALUE)
		AfxMessageBox(_T("Error OPeniong File"));
	else {
		CFile myfile((int)hFile);
		int key;
		DeptDetails* dd;

		int i;
		myfile.SeekToBegin();
		CArchive ar(&myfile, CArchive::load);

		dd = (DeptDetails*) ar.ReadObject( RUNTIME_CLASS(DeptDetails) );

			
//			  while ( (ar.Read(&dd, sizeof(dd))) != 0) {
//			dd->Serialize(ar);
//			i = dd->GetDeptNo();
//			deptMap.SetAt(i, dd);

			delete dd;
//		}
		
		dd->~DeptDetails();
		myfile.Close();
	}
	
	return deptMap;
}


Regardingly, for all CMap... DYNAMIC_SERIAL objectS ARE NOT supported, its only CMap where the object can be of DYNAMIC_SERIAL/IMPLEMENT_SERIAL. CMap was my first inital preference but by looking at other CMap classes, I opted them, but not on returning to CMap things are fine. I mean 0 errors 0 warnings. I only get error at SetAt in ReadDepartments(). Have I implemented the CArchive correctly in Write & Read Departments. Please check out that.

I have come back in VC++ after long time, so many things are new and many out of the mind also. Hope to get this woring correctly at the earliest.

Thanks

Terry

GeneralRe: Error with CArray, CMap Pin
Jijo.Raj1-Jun-08 23:11
Jijo.Raj1-Jun-08 23:11 
GeneralRe: Error with CArray, CMap Pin
Trupti Mehta2-Jun-08 2:09
Trupti Mehta2-Jun-08 2:09 
GeneralRe: Error with CArray, CMap Pin
Jijo.Raj2-Jun-08 4:27
Jijo.Raj2-Jun-08 4:27 
QuestionCannot run the exe of my application Pin
vijay_aroli30-May-08 2:55
vijay_aroli30-May-08 2:55 
QuestionRe: Cannot run the exe of my application Pin
David Crow30-May-08 3:15
David Crow30-May-08 3:15 
AnswerRe: Cannot run the exe of my application Pin
Mike Dimmick30-May-08 7:16
Mike Dimmick30-May-08 7:16 
QuestionHow to remove a folder and all its contents Pin
piul30-May-08 0:25
piul30-May-08 0:25 
QuestionRe: How to remove a folder and all its contents Pin
CPallini30-May-08 0:32
mveCPallini30-May-08 0:32 
AnswerRe: How to remove a folder and all its contents Pin
piul30-May-08 0:44
piul30-May-08 0:44 
GeneralRe: How to remove a folder and all its contents Pin
CPallini30-May-08 0:59
mveCPallini30-May-08 0:59 
GeneralRe: How to remove a folder and all its contents Pin
piul30-May-08 1:05
piul30-May-08 1:05 
AnswerRe: How to remove a folder and all its contents Pin
vijay_aroli30-May-08 0:59
vijay_aroli30-May-08 0:59 
AnswerRe: How to remove a folder and all its contents Pin
Michael Schubert30-May-08 1:43
Michael Schubert30-May-08 1:43 
AnswerRe: How to remove a folder and all its contents Pin
David Crow30-May-08 3:17
David Crow30-May-08 3:17 
AnswerRe: How to remove a folder and all its contents Pin
ThatsAlok20-Jul-09 1:01
ThatsAlok20-Jul-09 1:01 
QuestionVisual Studio 2005 intellisense now showing all the elements Pin
ComplexLifeForm29-May-08 23:32
ComplexLifeForm29-May-08 23:32 
AnswerRe: Visual Studio 2005 intellisense now showing all the elements Pin
Ahmed Charfeddine30-May-08 2:11
Ahmed Charfeddine30-May-08 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.