problem accessing member functions from LRESULT CALLBACK Function() { }
-
Problem Statement: SetWindowsHookEx() won't permit the 2nd parameter to be a function in a class. Therefore, I have created a separate global function in my .cpp file "MouseHookWndProc" that will be called. However, how is it possible to reach functions in my (Dialog) class from the global function "MouseHookWndProc" ? Source code:
//DIALOG CONSTRUCTOR
S2000_CP_DLG::S2000_CP_DLG(CWnd* pParent) : CDialog(S2000_CP_DLG::IDD, pParent)
{
mouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHookWndProc, GetModuleHandle(NULL), NULL);
}LRESULT CALLBACK MouseHookWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(mouseHook, nCode, wParam, lParam);char chTempText\[100\]; sprintf(chTempText,"MouseHook:0x%X",wParam); //S2000\_CP\_DLG::CpMessage(chTempText,0);//show mouse action on dialog return CallNextHookEx(mouseHook, nCode, wParam, lParam);
}
class S2000_CP_DLG : public CDialog
{
DECLARE_DYNAMIC(S2000_CP_DLG)
public:
void CpMessage(char* pszMessage, int nVal);// show messages in edit control
CEdit m_editMessages;
}My Attempt to solve it: The obvious solution for me was to make CpMessage() a static (as well as the m_editMessages since that member variable is used by the function). This compiled, however Linking failed:
error LNK2019: unresolved external symbol "public: static class CEdit S2000_CP_DLG::m_editMessages" (?m_editMessages@S2000_CP_DLG@@2VCEdit@@A) referenced in function "protected: virtual void __thiscall S2000_CP_DLG::DoDataExchange(class CDataExchange *)" (?DoDataExchange@S2000_CP_DLG@@MAEXPAVCDataExchange@@@Z) S2000_CP_DLG.obj
void S2000_CP_DLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);DDX\_Control(pDX, IDC\_MESSAGES, this->m\_editMessages);//Edit Control
}
The problem persists... and unfortunately adding "this->" to the DoDataExchange() didn't work :sigh: does anyone have any recommendations ?
-
Problem Statement: SetWindowsHookEx() won't permit the 2nd parameter to be a function in a class. Therefore, I have created a separate global function in my .cpp file "MouseHookWndProc" that will be called. However, how is it possible to reach functions in my (Dialog) class from the global function "MouseHookWndProc" ? Source code:
//DIALOG CONSTRUCTOR
S2000_CP_DLG::S2000_CP_DLG(CWnd* pParent) : CDialog(S2000_CP_DLG::IDD, pParent)
{
mouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHookWndProc, GetModuleHandle(NULL), NULL);
}LRESULT CALLBACK MouseHookWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(mouseHook, nCode, wParam, lParam);char chTempText\[100\]; sprintf(chTempText,"MouseHook:0x%X",wParam); //S2000\_CP\_DLG::CpMessage(chTempText,0);//show mouse action on dialog return CallNextHookEx(mouseHook, nCode, wParam, lParam);
}
class S2000_CP_DLG : public CDialog
{
DECLARE_DYNAMIC(S2000_CP_DLG)
public:
void CpMessage(char* pszMessage, int nVal);// show messages in edit control
CEdit m_editMessages;
}My Attempt to solve it: The obvious solution for me was to make CpMessage() a static (as well as the m_editMessages since that member variable is used by the function). This compiled, however Linking failed:
error LNK2019: unresolved external symbol "public: static class CEdit S2000_CP_DLG::m_editMessages" (?m_editMessages@S2000_CP_DLG@@2VCEdit@@A) referenced in function "protected: virtual void __thiscall S2000_CP_DLG::DoDataExchange(class CDataExchange *)" (?DoDataExchange@S2000_CP_DLG@@MAEXPAVCDataExchange@@@Z) S2000_CP_DLG.obj
void S2000_CP_DLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);DDX\_Control(pDX, IDC\_MESSAGES, this->m\_editMessages);//Edit Control
}
The problem persists... and unfortunately adding "this->" to the DoDataExchange() didn't work :sigh: does anyone have any recommendations ?
Create a global pointer of your class.
S2000_CP_DLG* pThis = 0;
In the constructor or the OnInitDialog function assign the address of the object to the pointer.
pThis = this;
Now you can access the class members using
pThis
.«_Superman_» I love work. It gives me something to do between weekends.
-
Create a global pointer of your class.
S2000_CP_DLG* pThis = 0;
In the constructor or the OnInitDialog function assign the address of the object to the pointer.
pThis = this;
Now you can access the class members using
pThis
.«_Superman_» I love work. It gives me something to do between weekends.