|
Can someone tell me why this isn't freeing up the memory like it suppose to?
Thanks
#include <afxwin.h>
#include <iostream.h>
class CDeeper : public CObject{
private:
CString *strTemp;
public:
CDeeper():strTemp(new CString){}
~CDeeper(){}
void setStr(CString setTemp){ *strTemp = setTemp; }
void Delete(){ delete strTemp; strTemp = NULL; }
};
class CTest : public CDeeper{
private:
int num;
CObList DeeperList;
CDeeper *pDeeper;
public:
CTest(){}
~CTest(){}
void setStr(int i){
num = i;
pDeeper = new CDeeper;
pDeeper->setStr("Hello");
DeeperList.AddTail(pDeeper);
}
void Delete(){
POSITION pos;
pos = DeeperList.GetHeadPosition();
while(pos){
pDeeper = (CTest *)DeeperList.GetNext(pos);
pDeeper->Delete();
delete pDeeper;
}
DeeperList.RemoveAll();
}
};
int main(){
POSITION pos;
CObList strList;
CTest *pTest;
int i;
for (i=0; i< 50000; i++){
pTest = new CTest;
pTest->setStr(i);
strList.AddTail(pTest);
}
pos = strList.GetHeadPosition();
while(pos){
pTest = (CTest *)strList.GetNext(pos);
pTest->Delete();
delete pTest;
}
strList.RemoveAll();
return 0;
}
|
|
|
|
|
Change CDeeper to:
class CDeeper : public CObject
{
private:
CString *strTemp;
public:
CDeeper(){}
~CDeeper(){}
void setStr(CString setTemp){ strTemp = new CString(setTemp); }
void Delete(){ delete strTemp; strTemp = NULL; }
};
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I found out I can do
class CDeeper : public CObject{
private:
CString *strTemp;
public:
CDeeper():strTemp(new CString){}
~CDeeper(){ delete strTemp; strTemp = NULL; }
void setStr(CString setTemp){ *strTemp = setTemp; }
void Delete(){ }
};
Now I need to figure out why the three cases are different
|
|
|
|
|
One additional question on this. I notice when I call delete pTest it calls the destructor again and strTemp at that point is pointing to an unknown location with no value.
Anyway to prevent that?
|
|
|
|
|
Hi this is my first time using MFC and I just created a basic MFC aplication where you can enter data and display a calculated result (dialogue based). However I need to incorporate some file input and output which i wrote using a win32 console application <fstream>. Is there an easy way to allow MFC to recongise <fstream> because atm its having none of it?
|
|
|
|
|
When CHtmlView completes loading document it steals focus. How to avoid this?
|
|
|
|
|
I have a program with an active x control. Before I can run the program properly, I need to locate the .ocx file, and then register the control. Just what is an ocx file? What does registering the active x control do?
Thanks.
Jerry
|
|
|
|
|
An OCX is simply a DLL with a different extension, nothing more, nothing less. If it supports self-regisration (and almost all do), it will export a function called DllRegisterServer. The writer of the OCX puts whatever functionality is necessary to register the OCX correctly in this function. This is typically just adding some registry keys.
Note that an OCX does not *have* to export a DllRegisterServer function - you could just list the registry entries needed for correct operation in a text document shipped with the OCX - but every commercial OCX I've ever come across does.
To register the OCX, load it using LoadLibrary , get a pointer to the DllRegisterServer function using GetProcAddress , and then call the function itself. DllRegisterServer is a void function that takes no parameters.
|
|
|
|
|
I have some problems with a c++ file containing about 7000 lines. Sometimes, Visual Studio copies some of the last lines of the file, and prints them at the bottom of the file... only problem is that it doesn't show them in the editor.. I have to reopen the file to find and delete the 'new' code.. anyone having the same problem??
I am using Visual Studio .NET 2003..
øivind
|
|
|
|
|
I think your problem is, that you have a file containing 7000 lines
You should find a way to split it.
I often find duplicate code in such code fragment -> make them functions.
If it is a Class.cpp it is probably the class is too big, tries to cover too much. Extract Classes from it.
HTH
Kind regards
Sawatzky
PS: No I never had that problem
|
|
|
|
|
I think I've read others complaining about that bug. Try searching the lounge.
Todd Smith
|
|
|
|
|
I have a dialog, which have a CEdit control inside. How can I let Dialog catches ( intercept ) the CEdit's keyboard input. I mean, I want dialog OnChar() be called, when user type in CEdit box.
Thanks ;P
|
|
|
|
|
Have you tried deriving a class from CEdit ?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Would you give me a explicit anwser?
|
|
|
|
|
Use ClassWizard (Ctrl+W) to open the New Class dialog, type a name for the new class and select CEdit from the Base class combobox.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
What's the equivenlent of ATL::CContainedWindow and ALT_MSG_MAP in MFC?
I'm after the IE "Shell Embedding" window from a CHtmlView.
Todd Smith
|
|
|
|
|
Hi,
i need to run a program from my VC++ app. In Delphi there was an "ExecuteFile" , can someone help me with the equivalent from VC++ ?
|
|
|
|
|
Try CreateProcess() or ShellExecute() .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
I am using CSplitterWnd::GetRowInfo and GetColumnInfo to get the height and width of one of the panes created by the splitter. It is working perfect until a certain height and width, but once I try to increase further (by moving the splitter to the right or bottom), the resize works perfect, however, I don't get correct values for the height and width. What happens is, at a certain value for height and width, MFC will return me the same value no matter how much I move the splitter to the right or bottom, even though I can see the the resizing is done perfectly well. And, these values are smaller on Windows 2003 and XP, compared to 2000, they are random values.
Thanks in advance. Any help is appreciated.
|
|
|
|
|
Is there a way to create a activex dialog window. Basically an windowed activex control.
Thanks
|
|
|
|
|
I am working on an SDI application , but have stripped out the Doc View Concept, just preserving the CMainfrm class . The component that I added was :
Two CDialog objects(same class) that I create from within the CMainFrm class . I have the following questions
1. I create the 2 Dialog objects and they show up just fine , but unlike a View their title bars are not highlighted in blue . I would really desire this feature as it tells the user which Dialog they are working with . Here are the styles that I assigned to the Dialog resource using the IDE :
Style = "Child"
Border = "Thin"
and checked the "Title" checkbox
2. I need to be assigning separate names to both of these dialogs . What is the API call to set the titleName : say like "MyDialog1" and "MyDialog2" as part of the title bar .
Any suggestions ?
|
|
|
|
|
you can do this in the dialog's OnInitDialog() :
this->SetWindowText("my dialog title");
or
this->SetWindowText(m_strTitle); where m_strTitle is a string previously stored (by the caller why not) with the title.
however, I am surprised to see you want a title-bar with a "child-style" dialog (which shouldn't have any).
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi,
I have a problem with a VC++ (6.0) dialog based application running under Windows XP. From a modal dialog, the user initiates some long-running activity, in a loop, that can take as much as 10 - 15 minutes to complete.
If during the processing, the user covers the modal dialog with another window, even for a second or two, and then re-exposes it and clicks in the dialog, on Windows XP, "Not Responding" is displayed in the window title bar, causing the user to believe the app has died... but of course it hasn't.
This behavior does not seem to occur under Windows 2000 or NT.
There are a whole host of reasons why it would not be a good idea, in this particular situation, to start a new thread to do the processing, freeing up the dialog to respond to whatever messages XP is sending to determine if it is alive.... so.... Short of a separate thread... any ideas would be really, really appreaciated
Thanks,
Doug
Doug Knudson
|
|
|
|
|
The only other approach is to implement a message loop within the long running function. This used to be general practice back in the 16 bit days and I think if you search here on codeproject, you'll likely find an article that describes how to implement what you are looking for.
Chris Meech
I am Canadian. [heard in a local bar]
Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Doug, check out the section "Responding to user input while performing a long task" in this[^] article.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|