function pointers
Sorry if this has been covered in another topic, the forums search engine doesn't appear to be working today.
I am trying to design a system where I have dialog classes and a CContextCmd class. I want the dialogs to add pointers to command handlers in themselves to the CContextCmd. Then, if appropriate, I want that CContextCmd to be able to call those functions in those objects. So here is fragments of my code:
typedef BOOL (__cdecl CWnd::*MENU_HANDLER_PTR)( CContextCmd * );
BOOL CContextCmd::ExecuteMenuCommandEx( CMap<CString, LPCTSTR, MENU_HANDLER_PTR, MENU_HANDLER_PTR> *map, CWnd* window, UINT command )
{
...
MENU_HANDLER_PTR func;
if( !done && map->Lookup( cmd, func ) )
{
done = (window->*func)( this );
}
...}
BOOL CVendors::OnMenuNew( CContextCmd *cmd )
{...}
I was under the impression that this worked because OnMenuNew gets called when it should. However, I have recently noticed that the value of window in ExecuteMenuCommandEx is different than the value of this in OnMenuNew, which is quite a large problem.
I read about this notation for calling functions somewhere in MSDN when I originally designed it, but I can't seem to find that information anywhere now.
Anybody know what this is about or where I can get more information? Thanks,
Chad Hogg
[1402 byte] By [
chhogg] at [2007-11-18 1:37:50]

# 1 Re: function pointers
Are you referring the the this pointer within CVendor or are you referring to the value of the cmd parameter?
Or are you referring to something else.
If you are referring to the value of the this pointer within CVentor, please provide the values and the derivation of CVendor.
# 2 Re: function pointers
I am referring to the this pointer in CVendor.
The derivation of CVendor would be:
class CVendors : public CEWPropSheet
class CEWPropSheet : public CDialog
class CDialog : public CWnd
In a sample run, the value of "window" is 0x00cb5c40, while when I am in the object that "window" is supposed to point to, "this" is 0x00d1747c, and it is not a valid window (ie the associated hWnd is ? ).
chhogg at 2007-11-10 8:55:05 >

# 3 Re: function pointers
If I understand your last post, the value being passed into your ExecuteMenuCommandEx is not correct...
From here I am guessing without seeing your CContextCmd class...
It does look like a valid address pointer.. Based on the value, I am willing to guess that it is a non hWnd child control of the dialog...
If you expand the fields of the incorrect value, does it look like it has valid state for an object, or a lot of junk?
If the m_hWnd of the incorrect address NULL or junk?
If the contents look somewhat reasonable, can you expand out the partent member to see if you can walk back to your expected value?
These are some of the things I would check first...