can i declare a variable of application class of my project??
Printable View
can i declare a variable of application class of my project??
Please give more details, what you want to do?
I have designed a project ,so what i read o=in various documention's is that InitInstance of the Application class of project is the entry point for the project, so by declaring a variable of application class in one of my normal cpp files (having a main()) and including the header files of this Application class, i guess i may display the GUI whenever i declare the variable??
Please ignore o= in above post
Well, well. You need to grab a copy of MFC programming to understand all that.
If you need Visual Studio to help, just create a Dialog based MFC application with MFC's New-Project wizard.
So m wrong??
It's not the question of being wrong or right. You need to understand basics of how MFC programs run (not too though!).
What you've read in documentation is correct, thus you are right. But you know how and why?
Yes, you can declare application-class variable, you are right. But what does it imply?
Well on declaring an object as in file
and have included all the required project required files am getting Following Errors:Code:#include "stdafx.h"
#include<iostream.h>
#include "Pflow.h"
int main(int argc, char* argv[])
{
printf("Hello World!\n");
CPflowApp app;
return 0;
}
main.obj : error LNK2001: unresolved external symbol "public: __thiscall CPflowApp::CPflowApp(void)" (??0CPflowApp@@QAE@XZ)
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/main.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
and the file Pflow.h the header file of my application class is given as:
Code:// Pflow.h : main header file for the PFLOW application
//
#if !defined(AFX_PFLOW_H__BB6F1EE1_33AA_4DF5_AF29_7A8DC123B309__INCLUDED_)
#define AFX_PFLOW_H__BB6F1EE1_33AA_4DF5_AF29_7A8DC123B309__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource1.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CPflowApp:
// See Pflow.cpp for the implementation of this class
//
class CPflowApp : public CWinApp
{
public:
CPflowApp();
int m_CurrentTool;
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPflowApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CPflowApp)
afx_msg void OnAppAbout();
afx_msg void OnBus();
afx_msg void OnCapacitor();
afx_msg void OnGenerator();
afx_msg void OnLine();
afx_msg void OnLoad();
afx_msg void OnTransformer();
afx_msg void OnUpdateBus(CCmdUI* pCmdUI);
afx_msg void OnUpdateTransformer(CCmdUI* pCmdUI);
afx_msg void OnUpdateLoad(CCmdUI* pCmdUI);
afx_msg void OnUpdateLine(CCmdUI* pCmdUI);
afx_msg void OnUpdateGenerator(CCmdUI* pCmdUI);
afx_msg void OnUpdateCapacitor(CCmdUI* pCmdUI);
afx_msg void OnText();
afx_msg void OnUpdateText(CCmdUI* pCmdUI);
afx_msg void OnDeleteBus();
afx_msg void OnUpdateDeleteBus(CCmdUI* pCmdUI);
afx_msg void OnDeleteCapacitor();
afx_msg void OnUpdateDeleteCapacitor(CCmdUI* pCmdUI);
afx_msg void OnDeleteGenerator();
afx_msg void OnUpdateDeleteGenerator(CCmdUI* pCmdUI);
afx_msg void OnDeleteLine();
afx_msg void OnUpdateDeleteLine(CCmdUI* pCmdUI);
afx_msg void OnDeleteLoad();
afx_msg void OnUpdateDeleteLoad(CCmdUI* pCmdUI);
afx_msg void OnDeleteTransformer();
afx_msg void OnUpdateDeleteTransformer(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_PFLOW_H__BB6F1EE1_33AA_4DF5_AF29_7A8DC123B309__INCLUDED_)
Well After changing my Settings->General to Use MFC using shared Dll i removed all the errors and could build the exe.....but know getting a runtime error as as soon as i execute my cpp file as written above:
it Prints the Output:
Hello World (at Console)
and displays error as:
Debug Assertion Failed!
File :appcore.cpp
Line :85
and the line 85 is:
ASSERT(AfxGetThread() == NULL);
i have earlier also recieved this error but could not help myself....
Why do you need CWinApp object?
Do you want to use MFC features?
You can create Console Application and add support to MFC.
how can i add that support to MFC
and i have already told you the need of CWinApp object.....
No you cannot! You application should be GUI, which, generally has WinMain, instead of main.Quote:
i guess i may display the GUI whenever i declare the variable??
So can you please give me any suggestion to accomplish this??
It would be hard for you to digest that you cannot do it that simply.
Grab a book of GUI/MFC/VC++ programming. Learn from some tutorials on the net. Create Dialog-based MFC application using wizard, and step-in each line of code, starting from InitInstance.
Understanding GUI/MFC programming will need few days, at least.
I'm not saying this to be rude, but just because it's the way it is. All your posts show that you don't yet have a grasp on some very basic concepts. You should really spend some time with a good tutorial book and get a really good handle on how everything works. Declaring a CWinApp instance inside the main function of a program doesn't make any kind of sense.