I found out the problem. I passed the size of the wide-char buffer in bytes to mbstowcs_s rather than the size in WORDS. Immediately I corrected this, everything started working fine. Thanks a lot.
Gbenbam
Posts
-
Please what is wrong with this my MFC code, what am I doing wrong? -
Please what is wrong with this my MFC code, what am I doing wrong?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:
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(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(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(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(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"),szMySch
-
Please can you create a means for one to quickly locate post in the C/C++/MFC forum .Please can you create a means for one to quickly locate post in the C/C++/MFC forum like the "Mine" link for Quick answers.
-
Please what is wrong with this my MFC code, what am I doing wrong?How do I edit my post? I'd like to but do not know how to go about it.
-
Please what is wrong with this my MFC code, what am I doing wrong?Normally, I code using win32 API. I just moved to MFC. I wrote this MFC code for a wizard but keep getting exceptions thrown. A first chance exception to be precise. My wizard is contained in an MFC extension dll. The wizard is lunch from an handler of CMainFrame. The CMainFrame from which the wizard is lunched is:
void CMainFrame::OnAddClassInfo()
{
CWinApp *pWinApp = AfxGetApp();FirstPage firstPage; ClassNameA className; ClassTerm classTerm; ClassSubjects classSubjects; ClassStaff classStaff; StopPage stopPage; className.SetAccess(m\_szAccessUsername,m\_szAccessPassword); className.SetClassInfo(m\_iClassTypeID, m\_iClassID); stopPage.SetClassInfoCombo(&m\_wndToolBar.m\_ArmName,&m\_wndToolBar.m\_ClassName,&m\_wndToolBar.m\_Session); CString stWizard; stWizard.LoadString(pWinApp->m\_hInstance,IDS\_CLASSINFO\_WIZARD,(WORD)LANGUAGE); ClassInfo ClassInfoWizard(stWizard,this); firstPage.SetPointer(reinterpret\_cast(&ClassInfoWizard)); className.SetPointer(reinterpret\_cast(&ClassInfoWizard)); classTerm.SetPointer(reinterpret\_cast(&ClassInfoWizard)); classSubjects.SetPointer(reinterpret\_cast(&ClassInfoWizard)); classStaff.SetPointer(reinterpret\_cast(&ClassInfoWizard)); stopPage.SetPointer(reinterpret\_cast(&ClassInfoWizard)); ClassInfoWizard.AddPage(&firstPage); ClassInfoWizard.AddPage(&className); ClassInfoWizard.AddPage(&classTerm); ClassInfoWizard.AddPage(&classSubjects); ClassInfoWizard.AddPage(&classStaff); ClassInfoWizard.AddPage(&stopPage); ClassInfoWizard.SetWizardMode(); if(ClassInfoWizard.DoModal() == ID\_WIZFINISH) { m\_eClassInfoView\_State = ENABLE; m\_eClassInfoChange\_State = ENABLE; m\_eStudentInfoAdd\_State = ENABLE; m\_eGradeInfoAdd\_State = ENABLE; }
}
The output window show the following error messages: First-chance exception at 0xfefefefe in SchPedestal.exe: 0xC0000005: Access violation. Unhandled exception at 0xfefefefe in SchPedestal.exe: 0xC0000005: Access violation. The program '[1456] SchPedestal.exe: Native' has exited with code -1073741819 (0xc0000005). Note: ClassInfo inherits from CPropertySheet, while the other objects inherit from CPropertyPage.
-
What is the format of the connection string used for mysql database access?What is the format of the connection string used for Mysql access in PHP?