|
|
Hi all.
I have this code:
MObject* object = new MObject();<br />
object->value=10;<br />
delete object;<br />
<br />
if (object!=NULL){<br />
int j=object->value;<br />
........<br />
}
Please help me.
Thanks
|
|
|
|
|
try{
int j = object->value;
}
catch(...){
// handling here
}
<font=sans-serif>|-|3llo Wo|2ld
|
|
|
|
|
Shuang. Wu wrote: try{
int j = object->value;
}
catch(...){
// handling here
}
Thanks, but this does not work.
I using VC++ 2005.
|
|
|
|
|
well, the code
int j = object->value;
could lead an unexpected result. sometimes exceptions like AV(Access Violation) could be thrown out, but not always.
<font=sans-serif>|-|3llo Wo|2ld
|
|
|
|
|
In general catch(...) is bad form. A general rule of exception handling is that you should only catch what you expect to be thrown.
Steve
|
|
|
|
|
Deleting an object doesn't invalidate the pointer to the object.
You need to do:
delete object;
object=null;
I'm not sure how to check if deleting of the object actually worked...anyone...anyone..
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Steve Echols wrote: You need to do:
delete object;
object=null;
Thanks, but if i do this code. The program does bot call:
int j=object->value;
and the error does not occur.
Above is a simple example, my problem is very complicate and i can not set NULL to object.
Thanks again.
-- modified at 2:55 Friday 14th April, 2006
|
|
|
|
|
Maybe I'm misunderstanding your problem...
If you delete an object, you can no longer access that object.
I.e. if you do:
delete object;
You are not allowed to access any member of the object, since it is "gone" (i.e. object->value will return something you don't expect).
If you do:
delete object;
object=null;
And then try to access object->value, you will most likely get an access violation (which is correct).
This is correct:
[By correct, I mean the code works, but don't do it this way, since you know you just deleted the object.]
delete object;
object=null;
if (!object)
{
// the object is deleted, you can't access it
}
else
{
int j = object->value;
}
Does that make sense?
- S
50 cups of coffee and you know it's on!
-- modified at 3:06 Friday 14th April, 2006
|
|
|
|
|
Steve Echols wrote: This is correct:
delete object;
object=null;
if (!object)
{
// the object is deleted, you can't access it
}
else
{
int j = object->value;
}
Yes, if i do that my problem will be fixed.
But this code is a simple problem. my problem complicate than that, and i don't permission to set object = NULL; i just have permission to access it and check it for existing or deleted.
So if you know how to check it for existing(not deleted) please give me that code.
try{}catch("what is here"){} or other way?
Thanks again.
|
|
|
|
|
From the code from your first post, you have permission to delete the object, but not set it to null? That's strange. I'd have to see some more code to see what's going on....
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
im developing a udp based client/service app that requires to be windows service apps.
serverService: a service that sends/recv the data to/from client.
i used WaitforSingleObject as a timer for serverService in a while(1) loop, that signals the event and serverService sends data to the clientService. the loop starts whenever the ServiceMain() is called from the SCM.
clientservice: a service that sends/recv data from server
similarly, i used WaitForSingleObject as a timer for my clientservice app, which sends the data to serverService very well.
but fortunately, both the services are unable to receive anything. even the OnReceive() Event is not getting triggered.
while i run the exact code using a Dialog-based app, both apps(client/server) runs fine and to the desired expectations.
Findings:
Therefore, just recognized after a fairly fine debugging that the neither serverService nor clientService was receiving any thing from each other, altho both services are sending the data.
it seems that, because both the services are in while loop therefore they can only do the tasks called from within the while loop.
Workaround:
so i guess i wud have to start another while(1) loop for both the services... that shud check and read the port for any prospective incoming message.
Results:
well, i did the above mentioned workaround, like while(1) ReceiveFrom(...), but once again, fortunately, it did not work.
Conclusion:
CAsyncSocket requires a message pump. Any ideas where shud i put my message_pump, the loop, so that i may get the exact message for the OnReceive to be called. Any snippets, links, articles?
Anybody has used the sockets in service??? Send() is S_OK, but How to Receive()??
Any ideas for the simple problem?
Best regards,
JT!
|
|
|
|
|
Anyone?
Best regards,
JT!
|
|
|
|
|
Windows services don't have message loops or perform hidden windows (usually). I did create a service one time that had a peekmessage loop and a hidden window bag in the good old days.
The best alternative is to use a different socket class that doesn;t depend on theses items.
I seem to remember using
http://www.codeproject.com/internet/casyncsocketex.asp[^]
in a service once. Check it out and see if it works for you or not.
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
Fiat justitia, et ruat cælum
|
|
|
|
|
Hello,
Using the MoveTo And LineTo function i can able to draw the line but now i want to draw the horizontal or vertical line then what should i do?
|
|
|
|
|
Whenever you draw horizontal line change the x co-ordinate only and when user push left button down then save the y-coordinate and use it for drawing
same case for vertical lines change the y-co-ordinate and persist x co-ordinate
good luck
Knock out "T" from CAN'T
You 'CAN' if you think you 'CAN'
|
|
|
|
|
Thaks for this valuabe suggestion. Please tell me how give the dimesion to that peritcular entity such as line or rectagle.Hope for ur positive response toward me as am just started to learn MFC.
|
|
|
|
|
MoveTo updates the current position. LineTo will draw a line from the current position to the specified point, and update the current position to the new point
To draw a rectangle, I believe you can do:
MoveTo(0, 0); // initial position
LineTo(5, 0); // draw top
LineTo(5, 5); // draw right
LineTo(0, 5); // draw bottom
LineTo(0, 0); // draw left
Does that help?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
in OnLButtonDown
..
if(MK_SHIFT)
{
if(abs(oldpt.y-newpt.y)>abs(oldpt.x-newpt.x))
newpt.x=oldpt.x
else(abs(oldpt.y-newpt.y)
|
|
|
|
|
Hello All of u,
Using the MFC i am able to draw the various gometric primitives such as line, circle, rectangle. But I want to give them the Dimension then How should i do this?
I am learing MFC from last few days.Guide me.
|
|
|
|
|
What you have to achive..??
Knock out "T" from CAN'T
You 'CAN' if you think you 'CAN'
|
|
|
|
|
Hi,
I want to store my application settings in registry, so that on the next launch i can use it [ window size, positioning,etc].
The registry keys has to be such that which can be used by guest users and normal users.
This has to work for all supported OS like Win 2k, Win XP Home and Professional with and without sp2.
Which registry key can i use HKEY_CLASSES_ROOT,
HKEY_LOCAL_MACHINE or
HKEY_CURRENT_USER.
Please suggest.
NancyAsath
|
|
|
|
|
If you want to allow the application settings to all users then simply add the registry keys into HKEY_LOCAL_MACHINE
and
If you want to restrict the application settings to particular users then simply add the registry keys into HKEY_CURRENT_USER
good luck...
Knock out "T" from CAN'T
You 'CAN' if you think you 'CAN'
|
|
|
|
|
I ported an application from VC++ to VC++.NET and the application is running fine in debug mode. But the same application is crashing in release mode. How can I determine the cause of it. Can anyone pls help.
---Arun.
|
|
|
|
|
Check the dynamic memory allocations ,array out of bounds etc.
Knock out "T" from CAN'T
You 'CAN' if you think you 'CAN'
|
|
|
|