Home > Software engineering >  VS2010 MFC class to invoke another class of other variables failed!
VS2010 MFC class to invoke another class of other variables failed!

Time:09-21

recently doing a dialog based PC, test and found a big problem, don't know BBS great god can you give me some directions,
 void CMFCBakDemoDlg: : OnCanDevcfg () 
{
INT_PTR nRes.
NRes=m_DevCfg. DoModal ();
If (IDCANCEL==nRes)
return;
}

 
Void CDeviceConfig: : OnBnClickedButtonStart ()
{
If (VCI_StartCAN (Devtype Devind, 0).=STATUS_OK)
{

} the else
{
GetDlgItem (IDC_BUTTON_Start) - & gt; In the operation of the SetWindowText (" "));
}
}

 
Void CMFCBakDemoDlg: : OnBnClickedButtonStart ()
{
If (VCI_StartCAN (m_DevCfg Devtype, m_DevCfg Devind, 0).=STATUS_OK)
{

} the else
{
GetDlgItem (IDC_BUTTON_Start) - & gt; In the operation of the SetWindowText (" "));
}
}



Devtype and Devind CDeviceConfig there are members of a class,

the above three fault code, including the third piece of code running failure, debugging found Devtype and Devind from 3 and 0, call m_DevCfg. Devtype and m_DevCfg Devind these two values are turned into 0? I don't know why appear this kind of problem, thought using VC6.0 + + can also be normal, I don't know why can't VS2010, hope the great spirit guide, thank you,

CodePudding user response:

Set the data breakpoint debugging operation

CodePudding user response:

This a few lines of code, can't see the problem, the key to find a modified m_DevCfg. Devtype and m_DevCfg Devind code,

CodePudding user response:

refer to the second floor lmj9401 response:
this few lines of code, can't see the problem, the key to find modified m_DevCfg. Devtype and m_DevCfg Devind code,

Can be changed with the aid of data breakpoints:
 # include & lt; time.h> 
#include
#include
Int main () {
Int a, b [11].//was b [10], to decide which words of cross-border, intentionally statement for b [11]

Srand ((unsigned int) time (NULL));//press F11 twice, such as yellow right arrow pointing to the bank, the debugging, the new breakpoint, new data breakpoints, address: & amp; B [10], byte count: 4, sure,
While (1) {//press F5, will stop in the following sentence, as a value of 10, b has been modified to corresponding to 0. [10]. One of the four,
B (11) (a=rand () %]=0;
Sleep (100);
B (11) (a=rand () %]=1;
Sleep (100);
B (11) (a=rand () %]=2;
Sleep (100);
B (11) (a=rand () %]=3;
Sleep (100);
B (11) (a=rand () %]=4;
Sleep (100);
}
return 0;
}

CodePudding user response:

reference zhao4zhong1 reply: 3/f
Quote: refer to the second floor lmj9401 response:

This a few lines of code, can't see the problem, the key to find a modified m_DevCfg. Devtype and m_DevCfg Devind code,

Can be changed with the aid of data breakpoints:
 # include & lt; time.h> 
#include
#include
Int main () {
Int a, b [11].//was b [10], to decide which words of cross-border, intentionally statement for b [11]

Srand ((unsigned int) time (NULL));//press F11 twice, such as yellow right arrow pointing to the bank, the debugging, the new breakpoint, new data breakpoints, address: & amp; B [10], byte count: 4, sure,
While (1) {//press F5, will stop in the following sentence, as a value of 10, b has been modified to corresponding to 0. [10]. One of the four,
B (11) (a=rand () %]=0;
Sleep (100);
B (11) (a=rand () %]=1;
Sleep (100);
B (11) (a=rand () %]=2;
Sleep (100);
B (11) (a=rand () %]=3;
Sleep (100);
B (11) (a=rand () %]=4;
Sleep (100);
}
return 0;
}

Seem to find the problem? But also don't know why?


If variables defined in the public again don't succeed, don't know what reason is this,

CodePudding user response:

M_DevCfg. Devtype
M_DevCfg=0?

CodePudding user response:

reference 5 floor schlafenhamster reply:
m_DevCfg. Devtype
M_DevCfg=0?

Use m_DevCfg domodal display child window, in the child Windows update Devtype variable is equal to 3, Devtype is associated with a control variable, after the EndDiagol (0) after exit the child Windows, the parent window m_DevCfg. Devtype access to data is zero,

CodePudding user response:

EndDiagol (0) after exit the child window, m_DevCfg has been destroyed, Devtype may have does not exist!

Usually m_DevCfg to save to the result of the ini file for the next time you start the program read the config

CodePudding user response:

refer to 7th floor schlafenhamster response:
EndDiagol (0) after exit the child Windows, m_DevCfg has been destroyed, Devtype has probably does not exist!

Usually m_DevCfg to save to the result of the ini file for the next time you start the program reads the config


M_DevCfg is defined as CDeviceConfig m_DevCfg, defined in the parent window, in the parent window m_DevCfg. Domadal, can open the window, but m_DevCfg. Devtype read is always zero, but in the public under the defined Devtype protected in CDeviceConfig won't appear this problem,
M_DevCfg. Devtype reads the value is, the value of the child window Settings,

CodePudding user response:

"But defines Devtype protected in CDeviceConfig won't appear this problem, in the public under the"
Protected:
Int XXXX.
Public://protected said: the end, began to public,
Int yyyy;

And directly put public: there, the problem elsewhere,

Your program have Config then start should have changed to later read the Config in the Config,
Usually in the Config variables defined in the app, take when using theApp. XXXX or AfxGetApp () - & gt; xxxx

CodePudding user response:

references 9 f schlafenhamster response:
"but in the public under the defined Devtype protected in CDeviceConfig won't appear this problem,"
Protected:
Int XXXX.
Public://protected said: the end, began to public,
Int yyyy; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related