|
For an MFC app, you don't need a _tmain() entry point. Use the CWinApp::InitInstance() and
CWinApp::ExitInstance() overrides for initialization and cleanup.
If you absolutely MUST have your own entry point then you'll need to look at the source code for
MFC's entry-point implementation and make sure you are covering all initialization and cleanup.
If the only reason you need to override the entry point is to check for memory leaks then
you can use a static object like your CWinApp object. I use this in my app module:
#ifdef _DEBUG
class _MemStateCheck
{
public:
CMemoryState oldMemState, newMemState, diffMemState;
_MemStateCheck();
~_MemStateCheck();
};
_MemStateCheck::_MemStateCheck()
{
oldMemState.Checkpoint();
}
_MemStateCheck::~_MemStateCheck()
{
newMemState.Checkpoint();
if( diffMemState.Difference( oldMemState, newMemState ) )
{
TRACE( "************************\n" );
TRACE( "Memory leaks Detected\n" );
TRACE( "************************\n" );
diffMemState.DumpStatistics();
diffMemState.DumpAllObjectsSince();
}
else
{
TRACE( "************************\n" );
TRACE( "No memory leaks Detected\n" );
TRACE( "************************\n" );
}
}
_MemStateCheck MemCheckObj;
#endif //#ifdef _DEBUG
|
|
|
|
|
|
There is no problem creating an app like this. The memory leak is a side effect of the MFC dlls unloading and is on shutdown only (and is likely due to the restrictions on unloading DLLs, rather than MFC itself.) If you link statically, the leak will go away.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Thank you very much for the explanation and for the solution, at the same time!
|
|
|
|
|
I m working in VC++/MFC application now.
It is dialog a based one.
In text bow, i created the CString textBox control for giving 10 digit numeric values.
When i submit the application , i receive the Application Error like 'The Instruction at "0x6c3b7f98" referenced memory at "0x00000048".The memory could not be read.'
After i will send it to the server.
In server it is received as a String.I don't know what's the problem.
So, give the solution this proplem.
Thanks.
Govindarajan.B
|
|
|
|
|
The error message says it all. You have tried (probably unintentionally ) to read from an
adddress you are not allowed to read from.
If you run in the debugger you should be able to trace back to the offending code when the
exception occurs.
There's a bad pointer problem somewhere.
Mark
|
|
|
|
|
I have a CListCtrl (m_ListCtrlStyled) on a form (A CFormView based application, developed in VC 6.0 SP6).
I initiate the CListCtrl in the OnInitialUpdate() function like the following.
<br />
<br />
DWORD dwStyle = ::GetWindowLong(m_ListCtrlStyled.m_hWnd, GWL_STYLE); <br />
dwStyle &= ~(LVS_TYPEMASK);<br />
dwStyle &= ~(LVS_EDITLABELS);<br />
SetWindowLong(m_ListCtrlStyled.m_hWnd, GWL_STYLE, dwStyle| LVS_REPORT|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);<br />
<br />
DWORD styles = LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES;<br />
ListView_SetExtendedListViewStyleEx(m_ListCtrlStyled.m_hWnd, styles, styles );<br />
<br />
m_ListCtrlStyled.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);<br />
<br />
<br />
TCHAR rgtsz[3][10] = {_T("SerialNumber"), _T("Doc"), _T("Score")};<br />
<br />
LV_COLUMN lvcolumn;<br />
CRect rect;<br />
m_ListCtrlStyled.GetWindowRect(&rect);<br />
for(int i=0;i<3;i++)<br />
{<br />
lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;<br />
lvcolumn.fmt = LVCFMT_LEFT;
lvcolumn.pszText = rgtsz[i];<br />
lvcolumn.iSubItem = i;<br />
lvcolumn.iOrder = i;<br />
switch (i)<br />
{<br />
case 0 :<br />
lvcolumn.cx = rect.Width()*1/10 ;
break;<br />
case 1:<br />
lvcolumn.cx = rect.Width()*7/10 ;
break;<br />
case 2:<br />
lvcolumn.cx = rect.Width()*2/10 ;
break;<br />
}<br />
<br />
m_ListCtrlStyled.InsertColumn(i, &lvcolumn);<br />
}<br />
<br />
CFont m_font;<br />
<br />
m_font.CreateFont(16, 0,0,0,FW_REGULAR, 0,0,0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier"); <br />
<br />
<br />
<br />
m_ListCtrlStyled.SetFont(&m_font);<br />
<br />
m_ListCtrlStyled.SetBkColor(RGB(247,247,255)); <br />
m_ListCtrlStyled.SetTextBkColor(RGB(247,247,255));<br />
<br />
<br />
The problem is that there was no change of the font when I change "arial" of m_font to other font name, say "courier".
i also tried with the following code , but failed again.
<br />
CWnd *pWnd=GetDlgItem(IDC_LIST2);<br />
CDC *pDC=pWnd->GetDC();<br />
CFont font;<br />
LOGFONT stFont;<br />
memset(&stFont,0,sizeof(LOGFONT));<br />
stFont.lfHeight=MulDiv(12,pDC->GetDeviceCaps(LOGPIXELSY),72); <br />
stFont.lfWeight=FW_NORMAL;<br />
stFont.lfCharSet=GB2312_CHARSET;<br />
strcpy(stFont.lfFaceName,"Arial");
font.CreateFontIndirect(&stFont);<br />
<br />
pWnd->SetFont(&font,TRUE);<br />
<br />
Please help me my friends
-- modified at 3:51 Saturday 2nd December, 2006
|
|
|
|
|
Isn`t UpdateData() needed here? Sorry if I`m wrong
|
|
|
|
|
Hi, Makakuin,
Makakuin wrote: Isn`t UpdateData() needed here? Sorry if I`m wrong
What do you mean. I did not use UpdateData in the my code.
|
|
|
|
|
Try to call UpdateData() right after all changes you need to make to ListCtrl as UpdateData really does "Update data"... This might help..
|
|
|
|
|
Is your CFont object going out of scope before any text is actually displayed?
Try making "CFont m_font;" a member variable instead of a local variable.
Mark
|
|
|
|
|
By the way gtsz[3][10] is too small. It should be gtsz[3][13]. (The strings really shouldn't be hard coded, but I assume this is a test app.)
And the problem as indicated above is that m_font is local and the font handle is being deleted. (The list control is robust enough that it recovers from this error.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
finaly, i found the answer, i should have declare m_font as a class member variable instead of a local variable, since i initiate the CListCtrl in OnInitialUpdate() and use it in another function. A local variable will go out of scope.
|
|
|
|
|
Hi
How can I change(set) the background color of my dialog box?
Thanks in advance
Taruni
|
|
|
|
|
Use SetDialogBkColor()
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
You should handle the WM_CTLCOLOR message.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi All,
I need to know how to set a default value in Combo Box. For example, right now I have a combo box with 3 times in it (Train, Bus, Both). I need to set "BOTH" as a default value in the combo box.
Thanks in advance
C++Prog
|
|
|
|
|
You can send the combobox a CB_SETCURSEL message (CComboBox::SetCurSel() in MFC).
Mark
|
|
|
|
|
Thanks a lot
Can I do it in 'Combo Box properties dialog'..or need to write a code for it?
C++Prog
|
|
|
|
|
Only at runtime, anytime after the Windows object (HWND) is created.
In response to the WM_INITDIALOG message is a good place
Mark
|
|
|
|
|
And...you'll want to do that AFTER you add items to the combobox!
Mark
|
|
|
|
|
I got it.....its working.....Thanks a bunch.
C++Prog
|
|
|
|
|
Here comes another thing...I need to do it dynamically. SetCurSel will make it static.
Thanks again
C++Prog
|
|
|
|
|
Preeti9 wrote: I need to do it dynamically. SetCurSel will make it static.
How so? It should just select/highlight the string, scrolling it into view if necessary.
|
|
|
|
|
o okay...I got it....
Thanks
C++Prog
|
|
|
|