Click to See Complete Forum and Search --> : Message Box
yamunae
April 15th, 2002, 06:12 AM
Hi,
I am using AfxMessageBox() API in my application.Sometimes the message box doesn't come up and when I debugged and saw found that the return value is 0 which means that there is no enough memory to display the message box.What do I do to solve this problem?
Thank You.
Yamuna.E.
Oyster
April 15th, 2002, 06:54 AM
Maybe you were passing invalid pointer to string to be displayed, or string was not zero-terminated. Try to check this out.
Regards.
Mike
yamunae
April 15th, 2002, 07:28 AM
Hi Mike,
Thanks for the reply.But the string I sent to the messagebox is valid and is null-terminated.But I forgot one thing to say that I call the message box in a thread function and this thread function takes the string(to be put in the message box) as its parameter(type BSTR).Could you get anything from this?
Thank You.
Yamuna.E.
Oyster
April 15th, 2002, 08:31 AM
I'm not sure about what you've exactly meant saying "thread function", but if it's function to be called via AfxBeginThread, I can see one more explanation of such behaviour.
If you're passing a string pointer to AfxBeginThread function, make sure this pointer is _not_ a locally allocated memory in caller function. In case it is, it will be invalid after caller function exits (AfxBeginThread returns immediately and don't wait the function it calls to complete).
You may overcome this problem by means of passing globally allocated pointer or, better, use class member to store your string and then pass this
pointer to AfxBeginThread (I assume that AfxBeginThread is called from within the method of this class).
Hope it helps.
Regards,
Mike
yamunae
April 16th, 2002, 12:19 AM
Yes , the thread function I have referred is called via CreateThread and I call this CreateThread within the method of this class.
And as you have told I have taken care of all memory related issues in passing the string.For that case I tried hardcoding the string in the message box.Even in that case I am getting the same problem of AfxMessageBox returning 0(not all times but often.However sometimes the message box comes up).
Thank You.
Yamuna.E.
Subject Re: Message Box
Posted by Oyster on 4/15/02 at 08:31 am
Rating not rated
I'm not sure about what you've exactly meant saying "thread function", but if it's function to be called via AfxBeginThread, I can see one more explanation of such behaviour.
If you're passing a string pointer to AfxBeginThread function, make sure this pointer is _not_ a locally allocated memory in caller function. In case it is, it will be invalid after caller function exits (AfxBeginThread returns immediately and don't wait the function it calls to complete).
You may overcome this problem by means of passing globally allocated pointer or, better, use class member to store your string and then pass
this
pointer to AfxBeginThread (I assume that AfxBeginThread is called from within the method of this class).
Hope it helps.
Regard
tgshaik
April 16th, 2002, 03:21 PM
Try using ::MessageBox function giving window handle as NULL .
yamunae
April 16th, 2002, 11:44 PM
Yes I tried using MessageBox with the first parameter as NULL and it works fine.Could you please explain the problem behind using AfxMessageBox?
Thank You.
Yamuna.E.
yamunae
April 16th, 2002, 11:47 PM
Hi,
I found an alternative.I tried using MessageBox API.Its working fine but I was not able to find the reason behind it.Do reply if you know.
Thank You.
Yamuna.E.
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.