Click here to Skip to main content
15,895,142 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CTabCtrl and Scrolling Pin
ThatsAlok7-Jul-05 0:10
ThatsAlok7-Jul-05 0:10 
GeneralRe: CTabCtrl and Scrolling Pin
Azghar Hussain7-Jul-05 0:54
professionalAzghar Hussain7-Jul-05 0:54 
Questionapproach to develope gave server application ? Pin
manxx6-Jul-05 21:09
manxx6-Jul-05 21:09 
GeneralSource Code creating Static Control at RunTime Pin
a_david1236-Jul-05 21:08
a_david1236-Jul-05 21:08 
GeneralRe: Source Code creating Static Control at RunTime Pin
Stlan6-Jul-05 22:34
Stlan6-Jul-05 22:34 
GeneralPlease help me! Pin
dSolariuM6-Jul-05 21:08
dSolariuM6-Jul-05 21:08 
GeneralSource Code creating Static Control at RunTime Pin
a_david1236-Jul-05 21:05
a_david1236-Jul-05 21:05 
GeneralRun-Time Check Failure #2 [edited] Pin
toxcct6-Jul-05 20:16
toxcct6-Jul-05 20:16 
Good Morning everybody,

i'd like to get your help on that too deep problem for my mind for the moment i am reflecting on.

I have a Dialog based MFC project that i am programming on VS7.1.
It's been compiling well, and i can execute it well as far as i enter in a certain state that causes the crash (so, if there is any syntactic/writing mistake on the code exposed, it is only on this post i make an error - as i don't Copy/Paste all the code given here).

i have two main classes, plus some extra types defined outside the classes as they are used by the two classes :

<code>CFactEditorDlg</code>  (the main dialog of the program)
    - FactEditorDlg.h
    - FactEditorDlg.cpp
 
<code>COptionsDlg</code>  (the option dialog of the program, that allow the user to set some display parameters)
    - OptionsDlg.h
    - OptionsDlg.cpp
 
FactEditorTypes.h (sample) :
<font color=blue>typedef enum</font> {
    <font color=green>//...</font>
} TStartingCallCountry;
 
<font color=blue>typedef enum</font> {
    <font color=green>//...</font>
} TEditorLanguage;
 
<font color=blue>typedef unsigned char</font> TDigitsInYears;
 
<font color=blue>typedef unsigned char</font> TDigitsInPhones;
 
<font color=blue>typedef struct</font> {
    TStartingCallCountry _StartingCallCountry;
    TEditorLanguage      _EditorLanguage;
    CString              _FileViewer;
    TDigitsInYears       _NbDigitsInYears;
    TDigitsInPhones      _NbDigitsInPhones;
} TEditorOptions;

TEditorOptions is a type made to transfer the 5 fields it encapsulates from CFactEditorDlg to the COptionsDlg, and to get them back (maybe modified) then.
This is done in the OnSclickOptions button as follow :
<font color=blue>void</font> CFactEditorDlg::OnSClickOptions() {
    <font color=green>// Creates EditorOptions with 5 data members</font>
    TEditorOptions EditorOptions = {
        m_StartingCallCountry,
        m_EditorLanguage,
        m_strFileViewer,
        m_ucNbDigitsInYears,
        m_ucNbDigitsInPhones
    };
    <font color=green>//Passes the datas through an overloaded constructor</font>
    COptionsDlg OptDlg(EditorOptions, m_strEditorVersion, <font color=blue>this</font>);
    <font color=blue>int</font> iResult = OptDlg.DoModal();
    <font color=blue>if</font> (iResult == IDOK) {
        <font color=green>// Validates the changes</font>
        <font color=green>//...</font>
    }
    <font color=blue>else</font> { <font color=green>// IDCANCEL</font>
    }
}

...and here is how the constructor of COptionsDlg treats the TEditorOptions parameter :
COptionsDlg::COptionsDlg(TEditorOptions& EditorOptions,
                         CString         EditorVersion,
                         CWnd*           pParent <font color=green>/* = NULL */</font>)
        : CDialog(COptionsDlg::IDD, pParent),
            m_EditorOptions(EditorOptions)    <font color=green>// m_EditorOptions is defined as a TEditorOptions&</font>
{
    ::strcpy(m_strEditorVersion, EditorVersion);
    <font color=red>m_strEditorVersion = EditorVersion</font>;    <font color=green>// m_strEditorVersion is now a Cstring</font>
    m_strDigitsInYears.Format(<font color=gray>"%d"</font>, m_EditorOptions._NbDigitsInYears);
    m_strDigitsInPhones.Format(<font color=gray>"%d"</font>, m_EditorOptions._NbDigitsInPhones);
}


now, the problem is that the Options dialog modifies well the datas, returns them to the CFactEditorDlg::OnSClickOptions() event handler correctly (i displayed the resulting values with a MessageBox), but just when i get out the OnSClickOptions() function, i get such a weird error :
Run-Time Check Failure #2 - Stack around the variable 'EditorOptions' was corrupted.

this is exactly what i get from the Run-Time, and i really can't understand what it can mean.

if it is of any help, i tried to see what happens in the debugger, and i saw that the local EditorOptions (local to OnSClickOptions()) is staying with the values it got from the option dialog, except the fact that the CString member _FileViewer is leaving its content.
the debbugger gives this :
Before :
    _FileViewer    {0x002fa000 "notepad"}                             ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >
 
After :
    _FileViewer    {0x002fa000 "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ"}    ATL::CStringT<char,StrTraitMFC_DLL<char,ATL::ChTraitsCRT<char> > >



if anybody knows, i'm all listening at you guys...


[edit]
i modified the m_strEditorVersion in both DialogBox classes into CString.
The error remains the same...
[/edit]



TOXCCT >>> GEII power
[toxcct][VisualCalc]
GeneralRe: Run-Time Check Failure #2 Pin
Bob Stanneveld6-Jul-05 21:09
Bob Stanneveld6-Jul-05 21:09 
GeneralRe: Run-Time Check Failure #2 Pin
toxcct7-Jul-05 0:18
toxcct7-Jul-05 0:18 
GeneralRe: Run-Time Check Failure #2 Pin
Bob Stanneveld7-Jul-05 0:26
Bob Stanneveld7-Jul-05 0:26 
GeneralRe: Run-Time Check Failure #2 [edited] Pin
toxcct7-Jul-05 0:31
toxcct7-Jul-05 0:31 
GeneralRe: Run-Time Check Failure #2 Pin
Bob Stanneveld7-Jul-05 0:32
Bob Stanneveld7-Jul-05 0:32 
GeneralRe: Run-Time Check Failure #2 Pin
toxcct7-Jul-05 5:32
toxcct7-Jul-05 5:32 
GeneralRe: Run-Time Check Failure #2 Pin
Bob Stanneveld7-Jul-05 5:45
Bob Stanneveld7-Jul-05 5:45 
Questionhow to uninstall U disk Pin
6-Jul-05 18:35
suss6-Jul-05 18:35 
AnswerRe: how to uninstall U disk Pin
David Crow7-Jul-05 5:07
David Crow7-Jul-05 5:07 
Generalswitch() function Pin
Anonymous6-Jul-05 18:35
Anonymous6-Jul-05 18:35 
GeneralRe: switch() function Pin
khan++6-Jul-05 19:22
khan++6-Jul-05 19:22 
GeneralRe: switch() function Pin
Bob Stanneveld6-Jul-05 20:44
Bob Stanneveld6-Jul-05 20:44 
GeneralRe: switch() function Pin
Anonymous7-Jul-05 8:18
Anonymous7-Jul-05 8:18 
GeneralRe: switch() function Pin
Bob Stanneveld7-Jul-05 19:51
Bob Stanneveld7-Jul-05 19:51 
GeneralRe: switch() function Pin
Maximilien7-Jul-05 0:38
Maximilien7-Jul-05 0:38 
Questionhow to use mfc in win32 dll? Pin
gohappy_19996-Jul-05 18:05
gohappy_19996-Jul-05 18:05 
AnswerRe: how to use mfc in win32 dll? Pin
ThatsAlok6-Jul-05 20:23
ThatsAlok6-Jul-05 20:23 

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.