|
if you "new" an object, then the destructor is only called when you "delete" it.
if you allocate the object on the stack, the destructor is called when the object goes out of scope.
one or the other (or you can explicitly call the destructor, but that's something you can't really do without knowing you're doing it)
-c
<font size=-2>
o(int O){putchar(O);}main(){float l[8],O,I=.05;char _;for(l[6]=15;l[6]<':';o
(10),l[5]=-'$'*I+l[6]++*I)for(l[7]=-5;l[7]<'@';l[4]=-'('*I+l[7]++*I,o(_?'?':':'))for
(*l=O=0,_=1;++_&&((l[2]=*l**l)+(l[3]=O*O)<4);O=*l*O+l[5]+O**l,*l=l[2]-l[3]+l[4]);}</font>
|
|
|
|
|
If you store a pointer to class A as member variable in class B, and class B is designed to delete the A object in its own destructor, you should reset the pointer to NULL when you manually delete object A. This will make it clear:
B:: ~B()
{
if (m_ptrA != NULL) {
delete m_ptrA;
}
}
B::someFunction()
{
m_ptrA = new A();
...;
delete m_ptrA;
m_ptrA = NULL;
} /ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
No. But if you haven't created your own copy c'tor and assignment operator a HANDLE wrapper class might use the compiler generated versions and then two object might try to release the same resoucrce when they are destructed.
|
|
|
|
|
Hi:
This may be a stupid question.
In a dialog box, a certain function is called when I press 'Add' button. This function adds data to the listbox and then goes through the loop which takes about 15 seconds. The listbox doesn't get repainted until this long procedure is over (in fact, the control disappears from the screen at all during that time).
Is there a way to refresh/repaint the control BEFORE this lengthy loop is called?
Thanks
|
|
|
|
|
UpdateWindow will update the contents. Also, another function for you to be aware of is SetRedraw which allows you to disable drawing for situations where you're doing a lot to the control and don't want the flicker - but instead want a complete redrawing of the control only when finished.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
In addition to Tom's suggestions, you shouldn't be repopulating the entire list box when you add an item. This is a common GUI mistake. Instead, keep the listbox in synch with your data store by simply adding/inserting a single element. This will make your GUI respond faster and appear more professional.
If you must repopulate the list box, show a busy cursor. Use AfxGetApp()->DoWaitCursor() to do this.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Ravi!
You are really taking the things out of context and causing utter confusion to the people who are looking for 'good' suggestions. Please look at a question twice or thrice before posting your suggestion.
Thanks
|
|
|
|
|
Yes, I'm well aware of the original question. What about my suggestion did you find not good or misleading?
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I should've read the question the 4th. time. Thanks!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I don't think you will listen the 'real' music even at the n'th time;P
|
|
|
|
|
I have a menu item to exit the application(MDI).
the title on the menu Item is "Exit".
what is the best(safest) way to terminate the application ?
|
|
|
|
|
|
Use the CWinApp::OnAppExit function if you want to mimic exactly how the MFC exits the app
By the way, the best way to figure things like this out is to look at the menu in your default MDI app. You'll see that the Exit menu item has an ID of ID_APP_EXIT.
Then, taking that if you search through the MFC source code (using Find in Files) you'll find the following message map for the CWinApp class.
BEGIN_MESSAGE_MAP(CWinApp, CCmdTarget)
ON_COMMAND(ID_APP_EXIT, OnAppExit)
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnUpdateRecentFileMenu)
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
END_MESSAGE_MAP()
This type of peeking into the MFC code is the best way to learn the "correct" way to program your apps.
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
I have made a resource file which defines what controls etc. are on my form, but how do i use that Resource on my main window? I know how to use it when creating a new dialog but not with the main window. And, i don't want to use MFC
thanks
|
|
|
|
|
hi,
i keep getting an error saying ": error C2196: case value '1' already used".
is there another way of having an or function in the middle
switch (get_textletter)
{
case 'a' || 'A':
get_textletter=0;
break;
case 'b'|| 'B':
get_textletter=1;
break;
case 'c'|| 'C':
get_textletter=2;
break;
|
|
|
|
|
'a' || 'A' is a logical or operation. Thus, the result is either 0 or 1.
try:
case 'A':
case 'a':
etc...
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
i think you would have to use the ascii values of the various letters instead.
|
|
|
|
|
There is no difference between 97 and 'a'.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
No, 'a' || 'A' does not mean case 'a' or case 'A' as you intent but case (conditon1 || condition2). Since at least one condition is non-zero, the result of the logical operation is true which is then converted to 1...
So your code in interpreted as:
Forum Visual C++
Subject: Re: is this wright?
Sender: Anonymous
Date: 12:31 30 Apr '02
hi,
i keep getting an error saying ": error C2196: case value '1' already used".
is there another way of having an or function in the middle
<br />
switch (get_textletter)<br />
{<br />
case 1: <br />
get_textletter=0;<br />
break;<br />
<br />
case 1: <br />
get_textletter=1;<br />
break;<br />
...<br />
and the compiler display an error because the same case appears more than once which is illegal.
What you want to do is to repeat the case statement like this:
<br />
switch (get_textletter)<br />
{<br />
case 'a':<br />
case 'A':<br />
get_textletter=0;<br />
break;<br />
<br />
case 'b':<br />
case 'B': <br />
get_textletter=1;<br />
break;<br />
...<br />
In any other case, if there are no break between 2 cases, a comment should be added to show that it was your intent and you not forget it. In case like this one, this is clear that you want to continue with the next case because every case appears unindented and one after the other (without any blank line)...
Philippe Mori
|
|
|
|
|
I am using TCP/IP socket, one application is running on Windows 2000, the other is on VxWorks(a real-time OS). What I am doing is: the Win app will send the VxWorks a request, say REQ_1, VxWorks received REQ_1, send back an acknoledge RESPONSE_1, Win app received RESPONSE_1, will send several KB data to VxWorks.
so the data flow is:
Win App VxWorks
REQ_1 ------------> (wait for reqeust)
(wait for response) <------------ RESPONSE_1
data -------------> (wait for data)
I found out that the first round of handshaking is very fast, it takes almost no time to finish everything (0.000000 according the my TRACE statement). But the second will take 0.08 or 0.09 or 0.10 seconds, and the following one would take 0.2 seconds. So there will be a limit 5 times of handshaking in a seconds. The bottleneck is for the Win App to receive the RESPONSE_1.
I tested it on a 10M LAN as well as on a 100M LAN, and get the same result.
Am I reaching any limit of software handshaking of TCP/IP socket? What did I do wrong?
|
|
|
|
|
Are you using TCP_NODELAY (turns off the Nagle algorithm) in the socket options? In Windows this defaults to 0.2 second delay for a send - I am not sure about VxWorks.
|
|
|
|
|
Wow, got it. After I set it, my program is like flying. Thank you so much!
|
|
|
|
|
Damn it, I thought it was the Nagle algorithm getting in the way, but I wasn't sure at all so I didn't say anything...
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Believe in yourself and be proud of yourself.
|
|
|
|
|
K I know theres loads on this topic but couldnt find anything which solves my dilemma.
I have a multi-threaded service with a time event which is monitored using cached information in a singleton com object i then wish to launch a process in a given directory i.e. zip some files up - Scheduler kindof app.
Now my problem is I've been using CreateProcess with no probs - however here it comes if I set the directory for which I wish to launch the process to have permissions for only a certain user - ie full control and i remove the everyone group then I get the error:
"the client does not have the required permissions."
Now I get this error
1: When Im debugging the service i.e. Im logged in as fred, and fred has the full access permissions on the directory in question.
2: When I set the service to use the same account and not the system account.
Now I looked into CreateProcessAsUser using LoginUser with the token - same problem. Not the best solution if it worked as i dont wish to pass or store the login credentials would much rather use the security credentials of the process so hence looked at: GetCurrentProcess, OpenProcessToken and AdjustTokenPrivileges. Still to no avail now i know i must be doing some wrong and missing something obvious so would appreciate any help.
Heres a snippet not clean but general idea:
HANDLE HToken = NULL;
DWORD dwAccess = TOKEN_ALL_ACCESS;
HANDLE hServProcess = GetCurrentProcess ();
if (OpenProcessToken (hServProcess, dwAccess, &HToken))
{
LUID luid;
TOKEN_PRIVILEGES newState, oldState;
DWORD rl;
LookupPrivilegeValue (_T(""), SE_SECURITY_NAME, &luid);
newState.PrivilegeCount = 1;
newState.Privileges[0].Luid = luid;
newState.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges (HToken, FALSE, &newState
, sizeof(oldState), &oldState, &rl))
{
rl = GetLastError();
return rl;
}
// execute zip process
if(CreateProcessAsUser(HToken
, NULL
, settings
, NULL
, NULL
, TRUE
, CREATE_NO_WINDOW
, NULL
, m_pSchedule->DirectoryBuff
, &st
, &proc) == 0);
}
Many thx to anyone who responds - sorry its a long post
|
|
|
|