Home Dashboard Directory Help

x64 MFC Macro Bug - ON_WM_POWERBROADCAST() / CWnd::OnPowerBroadcast / WM_POWERBROADCAST by Bordon


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 772549
Opened: 11/28/2012 9:48:07 AM
Access Restriction: Public
User(s) can reproduce this bug


In the macro ON_WM_POWERBROADCAST() in afxmsg_.h is a bug.

This problem only exist on x64 targests since the WPARAM and LPARAM value of the WM_POWERBROADCAST message will be cut.

The problem will occur if a PBT_POWERSETTINGCHANGE event occurs and the message LPARAM value is a pointer to a POWERBROADCAST_SETTING structure. In x64 systems the upper 32 bit of the LPARAM will cut in the OnPowerBroadcast handling since OnPowerBroadcase handles only UINT:
UINT CWnd::OnPowerBroadcast(UINT nPowerEvent, UINT nEventData)

The function should handle UINT_PTR instead of UINT.

Interesting fact, the CFrameWndEx::OnPowerBroadcast handles WPARAM and LPARAM and is x86 / x64 platform safe when you check the MFC help:


But the fact is the generated code is:
UINT CMainFrame::OnPowerBroadcast(UINT nPowerEvent, UINT nEventData)

It is the same wrong usage in CFRameWndEx::OnPowerbroadcase like the usage in CWnd, the difference is it is correct documented.

The problem is in VC2008 and VC2012 (both tested), I assume VC2010 is also affected.

Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:31 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Bordon on 1/17/2013 at 11:00 AM
How is it possible to solve this problem in VC2008 / 2010 / 2012 and using OnPowerBroadcast?
Posted by Microsoft on 11/29/2012 at 2:26 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 11/28/2012 at 9:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.