|
Did you want a managed assembly or a native Win32 application?
How did it fail?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Please forgive me if this is a silly question as I am a beginner at this MFC stuff. I am trying to debug an application that uses Modal dialog boxes. The application appears to slowly grow and grow. Just as a test I created a simple 2 dialog box app. A button on the first calls the second.
void CTESTDlg::OnButton1()
{
CDialog1 aDialog1;
aDialog1.DoModal();
}
Once the button on the parent Dialog has focus, holding the return Key down rapidy cycles the open/close of the child Dialog. If you watch the memory while doing this the app slowly grows. What am I missing here? I thought the Modal Dialog released all its memory when closed.
JerryL
|
|
|
|
|
your code posted has nothing wrong directly.
but as we don't know what CDialog1 class does internally when initializing and when handling events, i cannot say much than using a tool like Visual Leak Detector[^]...
|
|
|
|
|
|
Just that will not cause a memory leak.
do you allocate memory in the CDialog1 dialog that you do not free ?
|
|
|
|
|
There is no special initialisation code, this test app was built using the standard dialog application wizard and just using 2 default dialogs with just the parent having the added button to call the child dialog. I have tested the app with Visual Leak Detector and this does not report a leak. however when monitoring the programme size with performance monitor or Task Manager you can see the programme grow.
I found a bug listed by MS http://support.microsoft.com/kb/309121 ?
which suggests the following fix. This seems to fix the problem in my test app, the size grows once(?) but then stabilises.
void CParentDlg::OnButton1()
{
{
CDialog dlg( IDD_CHILD, this);
dlg.DoModal();
}
AfxGetApp()->OnIdle(1);
}
Unfortunately when tried in my real application I keep getting an unhandled exception Access violation in MFCO42d.DLL in OCCSITE.CPP in the function below.
DWORD COleControlSite::GetDefBtnCode()
{
if (m_dwMiscStatus & OLEMISC_ACTSLIKEBUTTON)
return (m_dwStyle & BS_DEFPUSHBUTTON) ?
DLGC_DEFPUSHBUTTON :
DLGC_UNDEFPUSHBUTTON;
else
return 0;
}
JerryL
|
|
|
|
|
If you are looking at the memory using the task manger, it doesn't indicate memory leaks.
If you click you button several times and see the memory increasing there, try to minimize your application to the task bar. If the Task Manager shows the memory returning to the smaller size, that means what you are seeing is the Process Working Set - it's managed automatically by Windows and released back to the OS as needed.
If this is the case, it is not a memory leak.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hello ppl need your help im working on an application and i have this code:
void CChatView::OnChatroomAddtoautojoin()<br />
{<br />
CString strOut;<br />
strOut.Format(IDS_AUTOJOIN_ADD, GetDocument()->m_strRoom);<br />
WriteSystemMsg(FALSE, strOut, g_sSettings.GetRGBOK());<br />
CClipboard::SetText((LPSTR)(LPCSTR)GetDocument()->m_strRoom);<br />
ManageAutojoins dlg;<br />
dlg.DoModal();<br />
}
This code is copy a room id in Clipboard and after is Launche an other dialog now what i need the other dialog is IDD_AUTOJOIN_MANAGER (ManageAutojoins) this dialog have a text box named: IDC_ADD_BOX need when the user press the Menu Button "OnChatroomAddtoautojoin" after the copy of ID to paste Clipboard data in IDC_ADD_BOX in IDD_AUTOJOIN_MANAGER dialog.
With 2 words i need when the IDD_AUTOJOIN_MANAGER (ManageAutojoins) Launche to have pasted in IDC_ADD_BOX the room ID (was coppyed in Clipboard).
Can someone give the command? because im stack over 2 hours...
Thanks,
Zhen-Xlogic
|
|
|
|
|
If you look in the class header file for CClipboard , you will probably find a GetText() function.
|
|
|
|
|
How can i syntax that function GetText() to add the text in IDC_ADD_BOX in IDD_AUTO_JOIN_MANAGER?
Because i try something and isnt work...
Thanks,
Zhen-Xlogic
|
|
|
|
|
|
YeaP!
Thanks a lot
Zhen-Xlogic
|
|
|
|
|
You're welcome
|
|
|
|
|
Please post the code that you tried, and the definition line from the CClipboard class header file.
|
|
|
|
|
Code that i tried:
void CChatView::OnChatroomAddtoautojoin()<br />
{<br />
CString strOut;<br />
strOut.Format(IDS_AUTOJOIN_ADD, GetDocument()->m_strRoom);<br />
WriteSystemMsg(FALSE, strOut, g_sSettings.GetRGBOK());<br />
CClipboard::SetText((LPSTR)(LPCSTR)GetDocument()->m_strRoom);<br />
<br />
OpenClipboard();<br />
m_strAdd = CClipboard::GetText();<br />
CloseClipboard();<br />
<br />
ManageAutojoins dlg;<br />
dlg.DoModal();<br />
}
CClipboard class header file:
<br />
#ifndef __CCLIPBOARD_H<br />
#define __CCLIPBOARD_H<br />
<br />
class CClipboard<br />
{<br />
public:<br />
static CString GetText(HWND hWnd = NULL);<br />
static BOOL GetText (LPSTR lpszBuffer,<br />
int nBufSize,<br />
HWND hWnd = NULL);<br />
<br />
static BOOL GetTextLength (unsigned long *pnSize,<br />
HWND hWnd = NULL);<br />
<br />
static BOOL SetText (LPSTR lpszBuffer,<br />
HWND hWND = NULL);<br />
};<br />
<br />
#endif
And the CClipboard class source file:
#include "stdafx.h"<br />
#include "Clipboard.h"<br />
<br />
<br />
BOOL CClipboard::GetText (LPSTR lpszBuffer, int nBufSize, HWND hWnd)<br />
{<br />
HGLOBAL hGlobal;
LPSTR lpszData;
unsigned long nSize;
<br />
OpenClipboard(hWnd);<br />
<br />
hGlobal = GetClipboardData(CF_TEXT);<br />
<br />
if (hGlobal == NULL) return FALSE;<br />
<br />
lpszData = (LPSTR)GlobalLock(hGlobal);<br />
nSize = GlobalSize(hGlobal);<br />
<br />
if(nSize >= (UINT)nBufSize) nSize = nBufSize - 1;<br />
<br />
for (UINT i = 0; i < nSize; ++i)<br />
*(lpszBuffer + i) = *(lpszData + i);<br />
*(lpszBuffer + i) = 0;<br />
<br />
GlobalUnlock(hGlobal);<br />
CloseClipboard();<br />
<br />
return TRUE;<br />
}<br />
<br />
<br />
BOOL CClipboard::GetTextLength (unsigned long *pnSize, HWND hWnd)<br />
{<br />
HGLOBAL hGlobal;
unsigned long nSize;
LPSTR lpszData;
<br />
OpenClipboard(hWnd);<br />
<br />
hGlobal = GetClipboardData(CF_TEXT);<br />
<br />
if (hGlobal == NULL) return FALSE;<br />
<br />
lpszData = (LPSTR)GlobalLock(hGlobal);<br />
nSize = GlobalSize(hGlobal);<br />
<br />
GlobalUnlock(hGlobal);<br />
CloseClipboard();<br />
<br />
*pnSize = nSize;<br />
return TRUE;<br />
}<br />
<br />
<br />
int CClipboard::SetText (LPSTR lpszBuffer, HWND hWnd)<br />
{<br />
HGLOBAL hGlobal;
LPSTR lpszData;
unsigned long nSize;
<br />
OpenClipboard(hWnd);<br />
EmptyClipboard();<br />
<br />
nSize = lstrlen(lpszBuffer);<br />
<br />
hGlobal = GlobalAlloc(GMEM_ZEROINIT, nSize+1);<br />
<br />
if (hGlobal == NULL) return FALSE;<br />
<br />
lpszData = (LPSTR)GlobalLock(hGlobal);<br />
<br />
for (UINT i = 0; i < nSize + 1; ++i)<br />
*(lpszData + i) = *(lpszBuffer + i);<br />
<br />
GlobalUnlock(hGlobal);<br />
SetClipboardData(CF_TEXT, hGlobal);<br />
CloseClipboard();<br />
<br />
return TRUE;<br />
}<br />
<br />
<br />
CString CClipboard::GetText(HWND hWnd)<br />
{<br />
<br />
CString strReturn;<br />
ULONG nLen = 0;<br />
char *buffer = 0;<br />
<br />
if(GetTextLength(&nLen, hWnd)){<br />
<br />
buffer = new char[nLen];<br />
GetText(buffer, nLen, hWnd);<br />
strReturn = buffer;<br />
delete buffer;<br />
buffer = 0;<br />
}<br />
return strReturn;<br />
}<br />
With this code in the CChatView::OnChatroomAddtoautojoin is build ok! but the Room ID is copy but isnt paste in IDC_ADD_BOX (The IDC_ADD_BOX is m_strAdd: DDX_Text(pDX, IDC_ADD_BOX, m_strAdd); ).
Why Isnt work my code is correct???
Thanks,
Zhen-Xlogic
|
|
|
|
|
- You don't need to call
OpenClipboard() and CloseClipboard() - they are called in the CClipboard functions.
- The
DDX_Text() statement will only be executed when DoDataExchange() is called. You have to do more than just set the value in m_strAdd - you have to force DoDataExchange() to be called. You can do this by calling UpdateData(FALSE); .
|
|
|
|
|
Because i lost you a bit, can you show me a code!? with the m_strAdd ???
Thanks,
Zhen-Xlogic
|
|
|
|
|
See Code that i tried: in your previous post.
|
|
|
|
|
Hello,
here is the full code:
http://www.paste.lt/paste/8207c95295928305310b7fbdb7e40c6d
I get compiler error:
[C++ Error] Unit5.cpp(109): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'Tkontaktai'
overloading is in 84-89 lines, but it doesn't work.
how could I overload it correctly?
Dj_Lord
|
|
|
|
|
Please post relevant code here using "pre" tags.
|
|
|
|
|
how to overload << operator correctly, because i am getting a compiler error.
full code:
#pragma hdrstop
#pragma argsused
#include <iostream.h>
class Tkontaktai {
char vardas[20];
char tel[12];
public:
Tkontaktai( ) {vardas[0] = tel[0] = '\0';}
void saugok(char *v, char *t) {strcpy(vardas, v); strcpy(tel, t);}
virtual void rodyk( ) {cout << vardas << ", " << tel;}
char *s_vardas( ) {return vardas;}
char *s_tel( ) {return tel;}
};
template <class T>
class Tnode {
Tnode *kitas;
public:
T duomenys;
Tnode (T re, Tnode * rod = NULL):duomenys(re), kitas (rod){ };
Tnode * Paimti ();
void Prijungti (Tnode *y){
kitas= y;
}
Tnode *Papildyti (Tnode *y){
y->kitas = this;
return y;
}
Tnode * Rkitas () {return kitas; }
};
template <class T>
class Tstack {
Tnode<T> *head;
public:
Tstack () {head= NULL; }
~Tstack<T>();
T Pop ();
void Push (T y);
int Empty();
ostream& operator<< (Tkontaktai* );
};
template <class T>
void Tstack<T>::Push(T y){
Tnode<T> * temp= new Tnode<T> (y,head);
head= temp;
}
template<class T>
T Tstack<T>::Pop(){
Tnode<T> *temp= head;
T re=head->duomenys;
head = head->Rkitas();
delete temp;
return re;
}
template <class T>
Tstack<T>::~Tstack<T>() {
Tnode<T> *temp;
while (head){
temp = head;
head = head->Rkitas();
delete temp;
}
}
template <class T>
int Tstack<T>::Empty(){
if(head)
return 0;
else
return 1;
}
template<class T>
ostream& Tstack<T>::operator<< (Tkontaktai* duom){
ostream& outstr;
outstr << duom->s_vardas() << " " << duom->s_tel() << endl;
return ostr;
}
main(){
Tstack<Tkontaktai> x;
Tkontaktai k;
char vardas[20];
char tel[12];
for (int i = 0; i<3; i++){
cout << "vardas: ";
cin >> vardas;
cout << "telefonas: ";
cin >> tel;
k.saugok(vardas, tel);
x.Push(k);
}
cout<< "Eileje buvo sie skaiciai:"<< endl;
while (!(x.Empty()))
cout << x.Pop() << endl;
system("pause");
}
Dj_Lord
|
|
|
|
|
Just the relevant code is all that's needed. Most of what you've provided has nothing to do with the compiler error.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
class Tkontaktai {
char vardas[20];
char tel[12];
public:
char *s_vardas( ) {return vardas;}
char *s_tel( ) {return tel;}
};
template<class T>
ostream& Tstack::operator<< (Tkontaktai* duom){
ostream& outstr;
outstr << duom->s_vardas() << " " << duom->s_tel() << endl;
return ostr;
}
template<class T>
Tstack::Pop(){
Tnode *temp= head;
T re=head->duomenys;
head = head->Rkitas();
delete temp;
return re;
}
main(){
cout << x.Pop() << endl;
}
overloading isn't working...
Dj_Lord
|
|
|
|
|
Dj_Lordas wrote: templateostream& Tstack::operator<< (Tkontaktai* duom){ ostream& outstr; outstr << duom->s_vardas() << " " << duom->s_tel() << endl; return ostr;}
Shouldn't this be:
class Tkontaktai
{
public:
friend ostream& operator<<( ostream&, const Tkontaktai& );
};
ostream& operator<<( ostream &os, const Tkontaktai &duom )
{
return os << duom.vardas << " " << duom.tel << endl;
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks, you are right! I was adding operator overloading in the wrong class...
Dj_Lord
|
|
|
|