Solved

this vs. (Cwnd*)m_hWnd #2

Posted on 1998-03-19
15
454 Views
Last Modified: 2013-11-19
Sorry, guys. The comment list was getting a little too long for my taste on that question, so let's start fresh. Here's what's going on:
Yes, I have tried changing that value. (to -1) Is that a valid thing to test out your idea, Shogi? In addition to that, thanks for the help guys, and here's that source:

#include "cdedit.h"

CDEdit :: CDEdit(int Mode)
{
      _validationMode = Mode;
}

void CDEdit :: OnKillFocus( CWnd* pNewWnd )
{
      char BoxText[255], NewText[255];
      double DummyD;
      CEdit::OnKillFocus(pNewWnd);      

      GetWindowText(BoxText, 254);
      if(strlen(BoxText) == 0)
            return;
      if(_validator.ConvertString(_validationMode, BoxText, NewText, &DummyD))
      {
            AfxMessageBox("Error with value!");
            SetWindowText(BoxText);
            return;
      }
      SetWindowText(NewText);

      //Default();
}  


BEGIN_MESSAGE_MAP(CDEdit, CEdit)
ON_WM_KILLFOCUS()
END_MESSAGE_MAP()
----------------------------------------
And the header:
#ifndef CDEDIT_H
#define CDEDIT_H

#include "stdafx.h"
#include "CDataVal.h"
class CDEdit : public CEdit
{
public:
      CDEdit(int Mode);
private:
      CDataValidation _validator;
      int _validationMode;
      void OnKillFocus( CWnd* pNewWnd );
      DECLARE_MESSAGE_MAP()
};
/*
// Defines for use with this class
// These specify the validation mode.
#define CD_AMOUNT_MODE       1//For cash amounts
#define CD_NUMBER_MODE       2//Just convert to value from string
#define CD_DISPLAY_DATE_MODE 3//In the form: mm/dd/yy
#define CD_PARAM_DATE_MODE   4//In the form: yyyymmdd from mm/dd/yy

#define CD_ERROR_DATE  5//General (no delimiters)
#define CD_ERROR_DAY   6
#define CD_ERROR_MONTH 7
#define CD_ERROR_YEAR  8
#define CD_ERROR_BAD_AMOUNT 9
*/
#endif
--------------------------------
So what do you think?
Thanks again.
0
Comment
Question by:Beatachon
  • 10
  • 5
15 Comments
 

Author Comment

by:Beatachon
Comment Utility
Keep in mind I'm programming a 16-bit dll here. Would that make any difference?

0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
(I would have suggested reducing the point value to 0 on the old question, marked it as answered and then opened up this new one.  Some people benefit from the *discussion*, not just the answer! :P)

   Anyway...  Back on topic..  I am running out of ideas on this one.  I cannot see, from the ST and source, what might be wrong.

   When the assertion fails, what is it failing on?  Is the Dialog (Create(...)) unable to resolve the passed CWnd into a valid window?  Try passing in a NULL CWnd (Dialogs do not HAVE to have a parent window).

   Also try this:  Override the constructor to accept a HWND instead of a CWnd*, and use CWnd::FromHandlePermanant() (or CWnd::FromHandle()) in the overridden Create(...) to get a CWnd*, and pass that to the Create() function.  Note that you might have the same problem as before:  CWnd::FromHandlePerm() might return NULL, which is basically what is happening now.

-=- James.
0
 

Author Comment

by:Beatachon
Comment Utility
I'm not passing in a parent window to the dialog as it is. So by default Null is going in. I'll try your FromHandlePermanent suggestion to pass the pointer to the create function. I'm also going to try creating just a plain old CEdit object to see what happens. Let's narrow it down. I'll keep you posted.
(I know, REALLY bad pun.)
0
 

Author Comment

by:Beatachon
Comment Utility
Well, no luck. I think it's pooping out at ASSERT_VALID(this); inside BOOL CMapWordToPtr::Lookup(WORD key, void*& rValue) const. But who's calling this? Is the Create function for the control calling it or is the dialog?
FromHandlePermanent(m_hWnd); gave me back the same thing the this pointer has.


0
 

Author Comment

by:Beatachon
Comment Utility
It's actually the AfxWndProc. The line is:
pWnd = CWnd::FromHandlePermanent(hWnd);
Just like you said, it is the FromHandlePermanent.
But whose? The control or the dialog. I've now seen the FromHandlePermanent work for the dialog.
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
  Let me see the stack trace again, please...

-=- James.
0
 

Author Comment

by:Beatachon
Comment Utility
Of course, the this pointer at that point Does look like this:
-this = 0x23D7:0x8030
  +CObject = {...}
  +classCMapWordToPtr = {...}
  +m_pHashTable = 0x0000:0x0000 protected
   m_nHashTableSize = 0 protected
   m_nCount = 0 protected
  +m_pFreeList = 0x0000:0x0000 protected
  +m_pBlocks = 0x0000:0x0000 protected
   m_nBlockSize = 0 protected

All nulled. Hmm.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Beatachon
Comment Utility
Here you go:
CMapWordToPtr::GetAssocAt()
CMapWordToPtr::Lookup()
CHandleMap::LookupPermanent()
CWnd::FromHandlePermanent()
AfxWndProc()
KRNL386!(1)
USER!(1)
CWnd::Create()
CEdit::Create()
CSelSort::OnInitDialog()
----------------------------------------------
This does all work when I build it in my win32 version, by the way. Is it something specific to 16-bit that I'm not doing properly?
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
  The Assertion is in CDEdit::Create(...).  From here, it looks like it cannot find the HWND (window) associated with the CWnd* that is passed into Create(...).

   Does the Control (CDEdit) exist within the DLL or does the Dialog and Control exist in the DLL?  Maybe that has something to do with it.

   Remember my last suggestion, about overriding Create(...)?  Try it again, but this time, create a CWnd and wrap the HWND with it (use CWnd::Attach(...)).  Make the CWnd a member of the CDEdit class.

-=- James.
0
 

Author Comment

by:Beatachon
Comment Utility
Does this look right to you?

in the header file under private I have:
CWnd _dummyCWnd;

and then implemented this:

BOOL CDEdit::Create(DWORD dwStyle, const RECT& rect, HWND HParent/*CWnd* pParentWnd*/, UINT nID)
{
      _dummyCWnd.Attach(HParent);
      return CWnd::Create("EDIT", NULL, dwStyle, rect, &_dummyCWnd, nID);
}

The reason I ask is that the Attach function asserts also. Any ideas?
0
 

Author Comment

by:Beatachon
Comment Utility
Asserts on this line:
ASSERT(FromHandlePermanent(hWndNew) == NULL);
                              // must not already be in permanent map
0
 
LVL 4

Expert Comment

by:jtwine100697
Comment Utility
  What about the DLL/Application question that I asked?

   FWIW, this is exactly what happens when you try to share CWnd (derived/using) objects between threads in Win32: Because each thread has its on handle-map, it cannot find mappings that were made in another thread.

   Attach() should not ASSERT unless (I believe) the HWND that was given to it is invalid.

   Try this...  What does IsWindow() (is that available under Win16?) return when you give it:

   o (In the dialog class, right before CDEdit::Create()) m_hWnd
   o (In CDEdit::Create()) HParent

   It should return a Non-Zero value indicating that the HWND that was given to it actually reperesents a valid (Existing) window.

-=- James.
0
 

Author Comment

by:Beatachon
Comment Utility
IsWindow returns good values.
I'm giving up. I'm just going to try to lay the controls out in the dialog template and then subclass them. Think it'll work?
Am I right in thinking that there is no UnSubclassWindow() in 16-bit? All I have to do is call SubClassWindow()?
(Answer this question. I wanna give you the points for helping me out.)
Thanks.
0
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 250 total points
Comment Utility
  I am not the only one that helped you out, but OK... :P

   AFAIK, all you have to do is call SubclassWindow() with your object to subclass an existing control.

-=- James.
0
 

Author Comment

by:Beatachon
Comment Utility
Yeah, you're right, but you spent the most time. Thanks to you to, Shogi.
See you guys later.
(I mean that. I'll probably be back)
There was a reason we left 16-bit behind.

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video discusses moving either the default database or any database to a new volume.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now