Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.
I used win32 API 'SetWindowsHookEx()' to override wndproc of excel.
For the versions below office365, codes are working well.
But for office365 excel, they do not work.

I just call 'XlWndProcStart()' and simply sends a message to excel 'WM_USER+WM_USER' like below.
HWND hwnd = ::FindWindowEx(NULL, NULL, "XLMAIN", NULL);
::SendMessage(hwnd, WM_USER + WM_USER, wp, lp);

I cannot guess what is wrong.
Please Help.
Thank you.

What I have tried:

Codes are simple.

__declspec(dllexport) void XlWndProcStart(DWORD threadId)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    m_hHookWndProc = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc,
        (HINSTANCE)AfxGetInstanceHandle(), threadId);
    if (m_hHookWndProc == NULL) {
        DWORD dw = GetLastError();
        TRACE("Error = %d, 0x%X\n", dw, dw);
    }
}

m_hHookWndProc has Value and it means SetWindowsHookEx() succeeded.
And CallWndProc() is like below.

LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if (nCode < 0) { // do not process the message 
		AfxMessageBox("if (nCode < 0)");
		return CallNextHookEx(m_hHookWndProc, nCode, wParam, lParam);
	}

	PCWPSTRUCT pMsg = (PCWPSTRUCT)lParam;

	switch (pMsg->message) {
	case WM_USER + WM_USER:
		AfxMessageBox("WM_USER + WM_USER");
		break;
	case WM_USER + WM_USER + 1:
		AfxMessageBox("WM_USER + WM_USER + 1");
        break;
	case WM_CLOSE:
		AfxMessageBox("XL CLOSE");
		break;
	default:
		break;
	}

	return CallNextHookEx(m_hHookWndProc, nCode, wParam, lParam);
}
Posted
Comments
Richard MacCutchan 11-Jul-22 7:05am    
You are sending the message WM_USER + WM_USER to Excel; what do you expect it to do?
Member 14877890 11-Jul-22 22:08pm    
I am testing whether messagebox pops up or not.
It pops up with excel version office2018 but not with office365. Please help me. Thanks.
Richard MacCutchan 12-Jul-22 3:26am    
Maybe it has something to do with the fact that Office 365 is an online service.
CHill60 12-Jul-22 12:00pm    
"Microsoft 365 for enterprise" is the desktop equivalent - I'd sort of assumed that's what the OP meant. But it would be quite funny if it wasn't :-)
Richard MacCutchan 12-Jul-22 12:03pm    
I assumed the opposite - maybe someone will clarify it for us. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900