|
First welcome Mr Moonen,whats up?did you have a good weekends?I think Spain is nice,whats spain like?
whitesky
|
|
|
|
|
I have created a class derived from an edit control. This class manages a double value as "the value" of that edit control. Whenever the value changes, I want to send a message to its parent, so that he can act upon it.
After the message has been sent, the application crashes and I get the send/dont send message from windows multiple times (depending on how many dialog controls there are on the dialog). This only happens in release mode.
The company where I work, had something to allow me to step through the code even though it was in release mode. This allowed me to see that the crash didn't happen in the function sending the message, but after the function was done or in functions in other threads. Still, the crash only happens after sending the message and when I quote the SendMessage function call out, no crash. Also, when I send another message instead of my own(e.g. WM_KEYDOWN), no crash.
The debugger always stops at this line of assembly code in !MFC42():
"mov esi,dword ptr [ecx+4]" with an acces violation. So I guess some memory gets corrupted while sending my message and the next thread that calls a standard MFC function crashes on it. How and Why, I have no clue.
I defined the message like this: "#define EN_APPLY (WM_APP + 1)" in the header file of the edit control.
Inside the message, I sent the dialog control id of the edit control as WPARAM, to allow the parent to distinguish between multiple edits.
In the parent header file I declare "afx_msg void OnApply(int iSenderCtrlId);"
In the parent cpp file I define "ON_MESSAGE(EN_APPLY, OnApply)" (with all the rest of those macros) and ofcourse, the implementation of the function (the content of which doesnt matter, because the error also appears when the function is empty)
I have this function to change the value of the edit and inform the parent:
void CEditWithScrollBar::SetWindowValue(double dValue, bool bNotifyParent)
{
if(m_dValue != dValue)
{
m_dValue = dValue;
if(bNotifyParent) (void)GetParent()->SendMessage(EN_APPLY, (WPARAM)GetDlgCtrlID()); // if I quote out this call, there is no crash.
}
CString sText;
CString sOldText;
sText.Format(m_sDisplayFormat, m_dValue);
GetWindowText(sOldText);
if(sText != sOldText)
{
SetWindowText(sText);
}
}
I found this link on errors happening in release and not in debug:
http://www.flounder.com/debug_release.htm
Maybe its of any use to anyone who wants to help out.
Thx in advance
|
|
|
|
|
Bana in Pyjama wrote: Whenever the value changes...
So do you have a handler for EN_CHANGE ?
Bana in Pyjama wrote: void CEditWithScrollBar::SetWindowValue(double dValue, bool bNotifyParent)
When is this method called?
Bana in Pyjama wrote: ...because the error also appears when the function is empty...
This implies that SendMessage() is not the culprit at all.
Bana in Pyjama wrote: I defined the message like this: "#define EN_APPLY (WM_APP + 1)" in the header file of the edit control.
Try using RegisterWindowMessage() instead, or use a constant other than 1.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
>When is this method called?
SetWindowValue is supposed to replace the CEdit::SetWindowText() function, so it could be called anywhere. Inside the class it is also called when the enter key is pressed on the control (setting the "multi line" and "want enter" styles in the designer and handling WM_ONKEYDOWN) and when WM_KILLFOCUS is received.
the error also appears when i leave the message handler of the EN_APPLY message (OnApply) empty, but the error doesnt appears when I quote out SendMessage(EN_APPLY) or when I sent any other message than EN_APPLY.
-- modified at 11:01 Monday 17th July, 2006
BTW, thx for the quick response!
|
|
|
|
|
Bana in Pyjama wrote: SetWindowValue is supposed to replace the CEdit::SetWindowText() function...
I'm not finding it in any header files or on MSDN? Is this a VC++ v6 issue?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Infact it's CWnd::SetWindowText()
|
|
|
|
|
Bana in Pyjama wrote: Infact it's CWnd::SetWindowText()
What's this in response to? I was asking about SetWindowValue() . I see it is a method of your CEditWithScrollBar class, but how/when it gets called has not been indicated.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
SetWindowValue() is my own function. I made it, to replace having to convert a numeric value to a string before calling SetWindowText(). So it is called whenever SetWindowText() would have been called. I did this because I noticed that this:
CString sText;
sText.format("%f", dValue);
m_edit.SetWindowText(sText);
and then:
CString sText;
m_edit.GetWindowText(sText);
dValue = atof(sText);
was all over my code.
Sorry for not beeing clear enough at the start.
|
|
|
|
|
Thx for the replies! But the answer from Steve S has solved my problem.
|
|
|
|
|
Change your handler to afx_msg LRESULT OnApply(WPARAM, LPARAM), have the method return 1L, and try that in both debug and release mode.
Steve S
Developer for hire
|
|
|
|
|
I'll try that right now.
Thx for the quick response too!
|
|
|
|
|
It works! Thanks a lot! I don't know why though?!
Why can't I just return a void and put different parameters for that handler?
|
|
|
|
|
Because the ON_MESSAGE macro expects your handling function to have that particular signature.
In debug build, it appears to work, but in release mode it will generally cause a crash, unless you are very unlucky. If you are unlucky, it will cause a crash in a completely unrelated place, which is extremely difficult to debug.
This is the second time in a week I've posted information about the same 'fix' on CP, so don't feel too bad; it's probably one of the top 10 MFC errors.
Steve S
Developer for hire
|
|
|
|
|
Message handlers are called by the framework and are expected to have a specific signature.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi,
I have a socket based internet application and would like to detect when a network connection goes up and down (preferrably the LAN connection), are there any events to register to?
When I move with my laptop from work to home, the network connection goes down and my chat application tries to reconnect because it sees that the socket was closed. The first reconnect attempt(s) fail and the next reconnect will be delayed for a longer time (e.g. an hour). When I am back home I would like to detect that the LAN connection is up again to trigger an immediate reconnect. I guess messenging application do something similar.
Cheers,
Mark
|
|
|
|
|
Have you considered the ISensNetwork interface?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thanks, I am trying to figure out which API to use. Just googling gives you many suggestions....
- IP Helper API: NotifyAddrChange()
- ISensNetwork: ConnectionLost() and ConnectionMade()
- Winsock: WSAIoctl(..., SIO_ADDRESS_LIST_CHANGE, ...)
- WinINet: InternetGetConnectedState()
- RasEnumConnections() together with InternetGetConnectedState()
Currently I am a bit lost, more details/experience would be great!
|
|
|
|
|
Any ideas out there why the Release build has lower performance than the Debug build.
build machine: Centrino Laptop, 1.6 GHz
test machine: PIII, 700MHz
project-settings-C/C++-processor: Blend*
The application consists of a MMAPI timer thread that posts messages to a view that displays graphics into the CDC.
The measure of performance is the amount of delay between timer event (sound) and WM_PAINT (picture).
thanx in advance
|
|
|
|
|
I would have to say it's the slower processor in your test machine.
|
|
|
|
|
Both Release and Debug builds were tested on the same machine (the P-III test machine). Thanks.
asta la vista baby
|
|
|
|
|
Hi !!!
I have Visual C++ 8.0 Compiler. When I have precompiled headers file "precomp.h" and its cpp file "precomp.cpp" which is empty, I get always this warning: "precomp.cpp: no public symbols found, archive members will be inaccessible". In other file than it is OK and and clever, but in precompiled headers file NOT. Does know somebody, what should I do?
Thanks !
Bye.
-:KNOX:-
|
|
|
|
|
knoxplusplus wrote: I get always this warning: "precomp.cpp: no public symbols found, archive members will be inaccessible". In other file than it is OK and and clever, but in precompiled headers file NOT. Does know somebody, what should I do?
Select that warning by single clicking on it. Do not double click. Press F1. This should give a detailed description as to what's the matter.
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
What line of code do I use to print a line of dashes?
|
|
|
|
|
This is a joke, right?
Steve S
Developer for hire
|
|
|
|
|
No, I'm serious. I am a beginner.
|
|
|
|