tags:

views:

23

answers:

1

I have a class. The problem now is, after a few attempt, I'm still in huge error. My problem is I don't know how to properly declare a new object for this class, inside another cpp file. I wanted to call/trigger the functions from this RebarHandler class from my other cpp file. I keep on getting problems like, 'used without being initialized', 'debug assertion failed' and so on.

In the other cpp file, I include the RebarHandler.h and did like this:

CRebarHandler *test=NULL;
test->setButtonMenu2();

When compile, I does not give any error. But, when run time, it gives error and my IE crash. I need help.

Below is the class I meant:

    #pragma once

    class CIEWindow;

    class CRebarHandler  : public CWindowImpl<CRebarHandler>{
    public:
CRebarHandler(HWND hWndToolbar, CIEWindow *ieWindow);
CRebarHandler(){};

~CRebarHandler();

BEGIN_MSG_MAP(CRebarHandler)
    NOTIFY_CODE_HANDLER(TBN_DROPDOWN, onNotifyDropDown)
    NOTIFY_CODE_HANDLER(TBN_TOOLBARCHANGE, onNotifyToolbarChange)
    NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, onNotifyCustomDraw)
    NOTIFY_CODE_HANDLER(TBN_ENDADJUST, onNotifyEndAdjust)
    MESSAGE_HANDLER(WM_SETREDRAW, onSetRedraw)
END_MSG_MAP()

// message handlers
LRESULT onNotifyDropDown(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled); 
LRESULT onNotifyToolbarChange(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled);
LRESULT onNotifyCustomDraw(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled);
LRESULT onNotifyEndAdjust(WPARAM wParam, LPNMHDR pNMHDR, BOOL& bHandled);
LRESULT onSetRedraw(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

// manage the subclassing of the IE rebar
void subclass();
void unsubclass();
void handleSettings();
    void setButtonMenu2();
bool findButton(HWND hWndToolbar);

    private:
// handles to the various things
HWND m_hWnd;
HWND m_hWndToolbar, m_hWndRebar, m_hWndTooltip;
HMENU m_hMenu;

int m_buttonID;
int m_ieVer;

CIEWindow *m_ieWindow;

// toolbar finding functions
void scanForToolbarSlow();
void getRebarHWND();
void setButtonMenu();

};

+1  A: 

It doesn't matter what CRebarHandler does, these lines are bad:

CRebarHandler *test=NULL; 
test->setButtonMenu2(); 

You have this pointer and you first say "it doesn't point to anything" and then you say "go ahead and use what the pointer is pointing to, to set the button menu." Not gonna happen.

Try:

CRebarHandler test; 
test.setButtonMenu2(); 

or

CRebarHandler test= new CRebarHandler(); 
test->setButtonMenu2(); 

Depending on the lifetime you want for test. You might want to use the constructor-that-takes-parameters instead of the default constructor. My point is that you have to have a CRebarHandler in order to call a method on it.

Kate Gregory