passin a variable from another class
-
HRESULT Cfirstw32mfcDlg::OnButtonOK(IHTMLElement* /*pElement*/) { UpdateData(TRUE); if(( EDIT1 == "" )&&( EDIT2 == "" )) { AfxMessageBox("You must provide a username and a password or click Cancel",MB_ICONSTOP); return NULL; } AfxGetApp()->WriteProfileString("Settings", "email", EDIT1); AfxGetApp()->WriteProfileString("Settings", "password", EDIT2); //CAddzonename* m_Zonename; //LPCTSTR m_Zonename = m_Zonename; /* if(m_Zonename) { AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename); } */ return 0; } ....................................................... // CAddzonename dialog header file class CAddzonename : public CDialog { DECLARE_DYNAMIC(CAddzonename) public: // global variable CString m_Zonename; ....................................................... i have tried this this ... CAddzonename* m_Zonename; CString m_Zonename2 = m_Zonename; if(m_Zonename2) { AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename2); } and return this ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(222) : error C2440: 'initializing' : cannot convert from 'CAddzonename *' to 'ATL::CStringT' with [ BaseType=char, StringTraits=StrTraitMFC ] No constructor could take the source type, or constructor overload resolution was ambiguous what am i doing wrong? kind regards, marco
-
HRESULT Cfirstw32mfcDlg::OnButtonOK(IHTMLElement* /*pElement*/) { UpdateData(TRUE); if(( EDIT1 == "" )&&( EDIT2 == "" )) { AfxMessageBox("You must provide a username and a password or click Cancel",MB_ICONSTOP); return NULL; } AfxGetApp()->WriteProfileString("Settings", "email", EDIT1); AfxGetApp()->WriteProfileString("Settings", "password", EDIT2); //CAddzonename* m_Zonename; //LPCTSTR m_Zonename = m_Zonename; /* if(m_Zonename) { AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename); } */ return 0; } ....................................................... // CAddzonename dialog header file class CAddzonename : public CDialog { DECLARE_DYNAMIC(CAddzonename) public: // global variable CString m_Zonename; ....................................................... i have tried this this ... CAddzonename* m_Zonename; CString m_Zonename2 = m_Zonename; if(m_Zonename2) { AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename2); } and return this ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(222) : error C2440: 'initializing' : cannot convert from 'CAddzonename *' to 'ATL::CStringT' with [ BaseType=char, StringTraits=StrTraitMFC ] No constructor could take the source type, or constructor overload resolution was ambiguous what am i doing wrong? kind regards, marco
Natural_Demon wrote: AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename2); I'm assuming that your application overrides WriteProfileString to take a CAddzonename pointer. AfxGetApp will return an instance of the base class, you need to cast it to the specialised class that contains this method. as it stands, it's trying to call the base class method, as that's all it can see. I think. It's kind of hard to wade through all of that badly formated code. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Natural_Demon wrote: AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename2); I'm assuming that your application overrides WriteProfileString to take a CAddzonename pointer. AfxGetApp will return an instance of the base class, you need to cast it to the specialised class that contains this method. as it stands, it's trying to call the base class method, as that's all it can see. I think. It's kind of hard to wade through all of that badly formated code. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
//CAddzonename* m_Zonename; <-- seems to be good, but how to use it?? if(m_Zonename) { AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename); } returns ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(224) : error C2065: 'm_Zonename' : undeclared identifier BTW, i tried that before Bad = knowing 2 much
-
//CAddzonename* m_Zonename; <-- seems to be good, but how to use it?? if(m_Zonename) { AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename); } returns ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(224) : error C2065: 'm_Zonename' : undeclared identifier BTW, i tried that before Bad = knowing 2 much
That's a whole different problem. m_Zonename does not exist in the class where you're trying to use it, obviously. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
That's a whole different problem. m_Zonename does not exist in the class where you're trying to use it, obviously. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
how smart u are, i found that also out, but what do i need or can i do about it?? Bad = knowing 2 much
-
how smart u are, i found that also out, but what do i need or can i do about it?? Bad = knowing 2 much
Natural_Demon wrote: how smart u are, i found that also out, but what do i need or can i do about it?? If you're going to be sarcastic, you can get stuffed. If you don't know how to declare or scope a variable, I suggest buying and reading C++ for dummies before asking questions here. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Natural_Demon wrote: how smart u are, i found that also out, but what do i need or can i do about it?? If you're going to be sarcastic, you can get stuffed. If you don't know how to declare or scope a variable, I suggest buying and reading C++ for dummies before asking questions here. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
i'm not getting sarcastic, but dont tell me it's obivious. i'm trying to find out how, i'm already reading stuf the whoile weekend andf i have read about creating a global variable, but when i copy(adapting the code afcourse) the code, visual doesn't accept it. somehow. Bad = knowing 2 much
-
i'm not getting sarcastic, but dont tell me it's obivious. i'm trying to find out how, i'm already reading stuf the whoile weekend andf i have read about creating a global variable, but when i copy(adapting the code afcourse) the code, visual doesn't accept it. somehow. Bad = knowing 2 much
Global variables are bad design anyhow. However, in C++, to declare something as global ( that is, not within the scope of any class ), it will still only be visible in files where the file that declares it is included. I found the best way to do this is to declare stuff in stdafx.h. But a better option would be to declare it within the class that you're trying to get at with AfxGetApp(), although you still need to cast that, as I said before. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Global variables are bad design anyhow. However, in C++, to declare something as global ( that is, not within the scope of any class ), it will still only be visible in files where the file that declares it is included. I found the best way to do this is to declare stuff in stdafx.h. But a better option would be to declare it within the class that you're trying to get at with AfxGetApp(), although you still need to cast that, as I said before. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
i tried to cast like this... CAddzonename* m_Zonename; //CString m_Zonename2 = m_Zonename; and it returns this ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(222) : error C2440: 'initializing' : cannot convert from 'CAddzonename *' to 'ATL::CStringT' with [ BaseType=char, StringTraits=StrTraitMFC ] if i do this ... CString m_Zonename2; CAddzonename* m_Zonename; m_Zonename2 = m_Zonename; j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(222) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'CAddzonename *' (or there is no acceptable conversion) ................................................................... CAddzonename* m_Zonename; //m_Zonename2 = m_Zonename; //if(m_Zonename) //{ AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename); } this will return ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(226) : error C2664: 'CWinApp::WriteProfileStringA' : cannot convert parameter 3 from 'CAddzonename *' to 'LPCTSTR' Bad = knowing 2 much
-
i tried to cast like this... CAddzonename* m_Zonename; //CString m_Zonename2 = m_Zonename; and it returns this ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(222) : error C2440: 'initializing' : cannot convert from 'CAddzonename *' to 'ATL::CStringT' with [ BaseType=char, StringTraits=StrTraitMFC ] if i do this ... CString m_Zonename2; CAddzonename* m_Zonename; m_Zonename2 = m_Zonename; j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(222) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'CAddzonename *' (or there is no acceptable conversion) ................................................................... CAddzonename* m_Zonename; //m_Zonename2 = m_Zonename; //if(m_Zonename) //{ AfxGetApp()->WriteProfileString("Settings", "Zonename", m_Zonename); } this will return ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(226) : error C2664: 'CWinApp::WriteProfileStringA' : cannot convert parameter 3 from 'CAddzonename *' to 'LPCTSTR' Bad = knowing 2 much
Natural_Demon wrote: CString m_Zonename2; CAddzonename* m_Zonename; m_Zonename2 = m_Zonename; Duh. Why do you expect to convert a string from an instance of your class ? Natural_Demon wrote: this will return ... j:\Visual Studio Projects\win32\firstw32mfc2\firstw32mfcDlg.cpp(226) : error C2664: 'CWinApp::WriteProfileStringA' : cannot convert parameter 3 from 'CAddzonename *' to 'LPCTSTR' Bloody hell. Follow my advice, or stop asking me. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer