AllocConsole(); //open the console window
freopen ("CONOUT$", "w", stdout); //set output available to this console
freopen("CONIN$","r",stdin); //set input avaiable to this console
more details on freopen Reference
Friday, May 15, 2015
Error: the application has failed to start because its side by side configuration is incorrect.
If you have met this error when you are running your distributed program in other machine,
One of the reasons is version mis-match. Someone may ask you to download the vcredist_x86.exe
from microsoft, but it maybe hard to find the right version.
Another method is to directly install the vcredist_x86.exe from your VC directory.
For VC 2005, probably the file is located at
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\vcredist_x86.exe
just copy this file to antoher machine and install it, it will then solve the version problem.
more details on Redistributing Visual C++ Files
One of the reasons is version mis-match. Someone may ask you to download the vcredist_x86.exe
from microsoft, but it maybe hard to find the right version.
Another method is to directly install the vcredist_x86.exe from your VC directory.
For VC 2005, probably the file is located at
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\vcredist_x86.exe
just copy this file to antoher machine and install it, it will then solve the version problem.
more details on Redistributing Visual C++ Files
Get System Window Resolution
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
more details on GetSystemMetrics Function
int cy = GetSystemMetrics(SM_CYSCREEN);
more details on GetSystemMetrics Function
List Directory
Get the header file "msdirent.h" from Internet or download here
you may put it in VC directory or just put it in your project folder.
Here is a sample program made by VC2005 to list out what is inside a directory. [download]
more details on C++ Forum
you may put it in VC directory or just put it in your project folder.
Here is a sample program made by VC2005 to list out what is inside a directory. [download]
more details on C++ Forum
Memory leak tracking for the "new" operator
Add these code on the top of the file that you would like to track memory leak in.
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#endif
#define new DBG_NEW
#endif // _DEBUG
After that, debugger will displays memory leak information in the output window after the program finished.
#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#endif
#define new DBG_NEW
#endif // _DEBUG
After that, debugger will displays memory leak information in the output window after the program finished.
Get pointers in MFC
1) Get CApp in anywhere:
AfxGetApp();
2) Get CDoc in CView:
CYouSDIDoc *pDoc=GetDocument();
3) Get CMainFrame in CApp:
the variable m_pMainWnd in CWinApp
or in anywhere:
CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();
4) Get CMainFrame in CView:
CMainFrame *pMain=(CMaimFrame *)AfxGetApp()->m_pMainWnd;
5) Get CView:
CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
CyouView *pView=(CyouView *)pMain->GetActiveView();
6) Get CDoc:
CDocument * pCurrentDoc =(CFrameWnd *)m_pMainWnd->GetActiveDocument();
7) Get CStatusBar and CToolBar:
CStatusBar * pStatusBar=(CStatusBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CToolBar * pToolBar=(CtoolBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);
8) Get Menu in Mainframe:
CMenu *pMenu=m_pMainWnd->GetMenu();
AfxGetApp();
2) Get CDoc in CView:
CYouSDIDoc *pDoc=GetDocument();
3) Get CMainFrame in CApp:
the variable m_pMainWnd in CWinApp
or in anywhere:
CMainFrame *pMain =(CMainFrame *)AfxGetMainWnd();
4) Get CMainFrame in CView:
CMainFrame *pMain=(CMaimFrame *)AfxGetApp()->m_pMainWnd;
5) Get CView:
CMainFrame *pMain=(CmaimFrame *)AfxGetApp()->m_pMainWnd;
CyouView *pView=(CyouView *)pMain->GetActiveView();
6) Get CDoc:
CDocument * pCurrentDoc =(CFrameWnd *)m_pMainWnd->GetActiveDocument();
7) Get CStatusBar and CToolBar:
CStatusBar * pStatusBar=(CStatusBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CToolBar * pToolBar=(CtoolBar *)AfxGetMainWnd()->GetDescendantWindow(AFX_IDW_TOOLBAR);
8) Get Menu in Mainframe:
CMenu *pMenu=m_pMainWnd->GetMenu();
Subscribe to:
Posts (Atom)