Click here to Skip to main content
15,867,568 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to replace \n with alt+enter while exporting to .CSV Pin
Jochen Arndt10-Dec-14 9:28
professionalJochen Arndt10-Dec-14 9:28 
QuestionPlease what is wrong with this my MFC code, what am I doing wrong? Pin
Gbenbam9-Dec-14 22:55
Gbenbam9-Dec-14 22:55 
SuggestionRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Jochen Arndt9-Dec-14 23:32
professionalJochen Arndt9-Dec-14 23:32 
GeneralRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Gbenbam11-Dec-14 0:20
Gbenbam11-Dec-14 0:20 
GeneralRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Jochen Arndt11-Dec-14 2:15
professionalJochen Arndt11-Dec-14 2:15 
AnswerRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Jochen Arndt9-Dec-14 23:36
professionalJochen Arndt9-Dec-14 23:36 
AnswerRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
David Crow10-Dec-14 17:28
David Crow10-Dec-14 17:28 
GeneralRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Gbenbam11-Dec-14 1:09
Gbenbam11-Dec-14 1:09 
ClassInfo inherits from CPropertyPage, while the other objects inherit from CPropertyPage.

The program successfully displays the wizards start page, but once I click next, this access violation occurs

Debugging shows that the access violation occurred in the following function:

C++
int ClassName::LoadSchoolName()
{
	CComboBox *pSchoolName = (CComboBox *)GetDlgItem(IDC_COMBO1);

	char szString[100];
	TCHAR szString1[100];
	INT_PTR iSchInfoID;
			
	try
	{
		//Get database path
		char szDatabaseFile[100];
		GetDatabaseA(szDatabaseFile,sizeof(szDatabaseFile));
		
	    //open database
		CppA::CppSQLite3DB db;
		db.open(szDatabaseFile);
			
		StringCbCopyA(szString,sizeof(szString),"SELECT SchInfoID,SchName,SchCity,SchState,SchCountry FROM SchInfo");
		CppA::CppSQLite3Query q  = db.execQuery(szString);
		if(q.fieldIsNull(0))
		{
			return 0;
		}
		
		//Gets first row
		//q.First();
		
		size_t size;
		const char *p;
		
		 while (!q.eof())
		 {
			 TCHAR szMySchName[50],szMySchCity[20],szMySchState[20],szMySchCountry[20];
			 long long iSchoolInfoID;

			 for (int fld = 0; fld < q.numFields(); fld++)
			 {
			
				 switch(fld)
				 {
				 case 0:
					 {
			
						iSchoolInfoID = q.getInt64Field(0);
						
					 }
					 break;
				 case 1:
					 {
						p = q.getStringField(1);
						DecryptString(const_cast<char *>(p),szString);
						mbstowcs_s(&size,szString1,sizeof szString1,szString,lstrlenA(szString));
						StringCbCopy(szMySchName,sizeof(szMySchName),szString1);

					 }
					 break;
				 case 2:
					 {

						p = q.getStringField(2);
						DecryptString(const_cast<char *>(p),szString);
						mbstowcs_s(&size,szString1,sizeof(szString1),szString,lstrlenA(szString));
						StringCbCopy(szMySchCity,sizeof(szMySchCity),szString1);
					 }
					 break;
				 case 3:
					 {
						p = q.getStringField(3);
						DecryptString(const_cast<char *>(p),szString);
						mbstowcs_s(&size,szString1,sizeof(szString1),szString,lstrlenA(szString));
						StringCbCopy(szMySchState,sizeof(szMySchState),szString1);

					 }
					 break;
				 case 4:
					 {
						p = q.getStringField(4);
						DecryptString(const_cast<char *>(p),szString);
						mbstowcs_s(&size,szString1,sizeof(szString1),szString,lstrlenA(szString));
						StringCbCopy(szMySchCountry,sizeof(szMySchCountry),szString1);

					 }
					 break;
				 }
			 }

			TCHAR szSchoolName[100];
			StringCbPrintf(szSchoolName,sizeof szSchoolName,_T("%s,%s,%s,%s"),szMySchName,szMySchCity,szMySchState,szMySchCountry);
			
			int i = pSchoolName->AddString(szSchoolName);//This is where the access violation occurred.

			pSchoolName->SetItemData(i,(DWORD_PTR)iSchoolInfoID);
											
			q.nextRow();

		 }
	     pSchoolName->SetCurSel(0);
		return 1;
	}
	catch(CppA::CppSQLite3Exception & e)
    {
		char szString[100];
		StringCbPrintfA(szString,sizeof(szString),"Error Code: %d\n Error Mesage: %s",e.errorCode(),e.errorMessage());
        MessageBoxA(NULL,szString,"Load shc name Error",MB_OK);
		return 0;
	}
	catch(double dError)
	{
		return 0;
	}
	return 0;
		
}


Actually, at the start the property page objects were members of the PropertySheet object.

Also, initially, the LoadSchoolName function was part of a win32 dll( I made it so for maintenace purpose) which the MFC extension dll ClassInfo.dll load or links with.

But when access violation kept occuring at that location of the function, I decided to make the function a member function in the MFC extension DLL, rather that a win32 dll.

Well, that did not solve the problem. So, I read through msdn and saw that example on DoModal() did not make the property pages member of the propertysheet object, so I decided to try that next, but still the same problem.

Shown below is the function that calls the LoadSchoolName function:

C++
BOOL ClassName::OnInitDialog()
{
	CPropertyPage::OnInitDialog();

	ClassInfo * pPropertySheet = (ClassInfo *)m_Pointer;
	
	LoadSchoolName();

	CComboBox *pCombo2 = (CComboBox *)GetDlgItem(IDC_COMBO2);
	int i = 0;
	while(*szClassType[i])
	{
		pCombo2->AddString(szClassType[i]);
		i++;
	}
	pCombo2->SetCurSel(0);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


The OnInitDialog function loads various school names from data base and uses them to fill the stated combobox. Like I said the wizard displays the wizard's start page , but each time I click next, the the access violation occurs.

If I comment out the LoadSchoolName function, the wizard successfully load the next Property page , but with an empty combobox.

So I decided to replace the combobox pointer in the LoadSchoolName function with a
C++
CArray<ULONG_PTR> 
Object( I cast each SchoolName TCHAR pointer to ULONG_PTR using a reinterpret_cast. So that I call add the strings to the combobox from the CArray object.

On doing this , access violation occures at the point in the code where I call CArray
C++
<ULONG_PTR>.Add(
).

It appears thar whetther I try to add the string to a combobox or an array, each time I attempt to addd the school name string, access violation occurs. I don't just understand why.

Can some one here, help?
GeneralRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Freak3011-Dec-14 3:11
Freak3011-Dec-14 3:11 
GeneralRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Richard MacCutchan11-Dec-14 6:39
mveRichard MacCutchan11-Dec-14 6:39 
GeneralRe: Please what is wrong with this my MFC code, what am I doing wrong? Pin
Gbenbam16-Dec-14 20:22
Gbenbam16-Dec-14 20:22 
QuestionVariable in flash memory - how to write? Pin
elelont29-Dec-14 20:43
elelont29-Dec-14 20:43 
AnswerRe: Variable in flash memory - how to write? Pin
Jochen Arndt9-Dec-14 21:33
professionalJochen Arndt9-Dec-14 21:33 
GeneralRe: Variable in flash memory - how to write? Pin
elelont29-Dec-14 22:39
elelont29-Dec-14 22:39 
GeneralRe: Variable in flash memory - how to write? Pin
Jochen Arndt9-Dec-14 23:28
professionalJochen Arndt9-Dec-14 23:28 
GeneralRe: Variable in flash memory - how to write? Pin
elelont210-Dec-14 0:06
elelont210-Dec-14 0:06 
QuestionC/C++ files with "Ex" suffixes Pin
david211149-Dec-14 12:10
david211149-Dec-14 12:10 
AnswerRe: C/C++ files with "Ex" suffixes Pin
Garth J Lancaster9-Dec-14 13:25
professionalGarth J Lancaster9-Dec-14 13:25 
GeneralRe: C/C++ files with "Ex" suffixes Pin
David Crow9-Dec-14 16:49
David Crow9-Dec-14 16:49 
AnswerRe: C/C++ files with "Ex" suffixes Pin
«_Superman_»9-Dec-14 19:05
professional«_Superman_»9-Dec-14 19:05 
GeneralRe: C/C++ files with "Ex" suffixes Pin
david2111412-Dec-14 3:32
david2111412-Dec-14 3:32 
GeneralNM_CUSTOMDRAW in an ATL dialog based application Pin
aks.9-Dec-14 3:00
aks.9-Dec-14 3:00 
QuestionRe: NM_CUSTOMDRAW in an ATL dialog based application Pin
Richard MacCutchan9-Dec-14 6:03
mveRichard MacCutchan9-Dec-14 6:03 
QuestionA Chinese blog about integrating MS Detours Library and Mhook library Pin
Jamming18-Dec-14 15:11
Jamming18-Dec-14 15:11 
AnswerRe: A Chinese blog about integrating MS Detours Library and Mhook library Pin
Garth J Lancaster8-Dec-14 16:32
professionalGarth J Lancaster8-Dec-14 16:32 

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.