On Feb 15, 9:37 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
See below...
On 15 Feb 2007 02:00:04 -0800, neelag...@hotmail.com wrote:
Joseph,
Thanks for the reply.
The code is fairly simple -
void CMyCombo::OnNcDestroy()
{
CString str;
DWORD dwErr;
SetLastError(0);
****
Do not SetLastError
****>GetWindowText(str);
****
Sorry, by OnNcDestroy, this function is illegal. The client area, that held the text, is
already gone. So this code cannot possibly work.
****>dwErr = GetLastError();
TRACE(_T("Last Error = %d"), dwErr); // return 1400 ==
ERROR_INVALID_WINDOW_HANDLE
****
That's what I would expect.
****>}
As far as dealing with the error, there isn't anything I can do. The
window is already invalid so I wont be able to get the text. All I
*could* do was to get the text in OnDestroy() and store it to be
referred to in OnNcDestroy().
****
Why would you want to refer to it in OnNcDestroy? OnNcDestroy is so rarely used that in
over a decade of MFC programming I've never found a reason to want to use it. We
typically use PostNcDestroy in MFC, after the window is well and truly gone. Since in
OnNcDestroy there's nothing useful left, there is no need to use this function.
Your life will be greatly simplified if you forget this function exists. And, I should
add, you should not need the text in PostNcDestroy either. What are you doing with the
text that you think you need to get it after the window is destroyed? What's wrong with
doing what you need to do in OnDestroy?
****
Thanks,
Neel.
On Feb 13, 11:59 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
Show the code.
Note that a successful API call rarely changes the value returned by GetLastError(), that
is, for nearly every API call the following code is nonsensical:
APICall(...);
if(::GetLastError() != ERROR_SUCCESS) ...
The only valid approach is
if(!APICall(...))
{
DwORD err = ::GetLastError();
... deal with error
}
joe
On 13 Feb 2007 00:12:37 -0800, neelag...@hotmail.com wrote:
Hi,
I have a custom combobox exported from dll and I use GetWindowText()
to get its text on WM_NCDESTROY. Now, it is understandable if I got
ERROR_INVALID_WINDOW_HANDLE as last error (GetLastError()), but, it
only happens in some of the applications that load the dll from which
this class is exported. For rest of the applications that use this
class exported from dll, everything works fine. Is there a reason why
I should get the error only in some applications and not in others?
Thanks in advance,
Neel.
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm- Hide quoted text -
- Show quoted text -
Thanks for the reply. Thats what I did as a solution. I got the text
in OnDestroy() and then referred it in OnNcDestroy(). The code in
OnDestroy() specially when its been written by someone else. The
didnt with remaining ones.