I'm trying to add an additional button into a toolbar in Internet Explorer.
I assumed the implementation to be straight forward, and am currently using this code:
TBBUTTON buttonToAdd;
ZeroMemory( &buttonToAdd, sizeof( TBBUTTON ) );
buttonToAdd.iBitmap = 1;
buttonToAdd.idCommand = 1;
buttonToAdd.fsState = TBSTATE_ENABLED;
buttonToAdd.fsStyle = BTNS_BUTTON|BTNS_AUTOSIZE;
LRESULT insertButtonResult = SendMessage( hWndToolbar, TB_INSERTBUTTON, 0, (LPARAM)&buttonToAdd );
When the message is sent, Internet Explorer will crash 90% of the time (10% of the time, I get a somewhat broken button on the toolbar) with the following exception:
Unhandled exception at 0x000007FEFB97DDFA (comctl32.dll) in iexplore.exe: 0xC000041D: An unhandled exception was encountered during a user callback.
Given that the results aren't consistent, I assumed some sort of memory layout issue. So I tried to send TB_INSERTBUTTONA
instead (my application defaults to TB_INSERTBUTTONW
), but that has no effect on the issue.
I also tried both 32 and 64 builds of my application, both have the same result.
I took a look at the callstack of iexplore.exe
, which looks like this:
comctl32.dll!CToolbar::TBInputStruct(struct _TBBUTTONDATA *,struct _TBBUTTON const *) Unknown
comctl32.dll!CToolbar::TBInsertButtons(unsigned int,unsigned int,struct _TBBUTTON *,int) Unknown
comctl32.dll!CToolbar::ToolbarWndProc(struct HWND__ *,unsigned int,unsigned __int64,__int64) Unknown
comctl32.dll!CToolbar::s_ToolbarWndProc(struct HWND__ *,unsigned int,unsigned __int64,__int64) Unknown
user32.dll!UserCallWinProcCheckWow() Unknown
user32.dll!DispatchClientMessage() Unknown
user32.dll!__fnDWORD() Unknown
ntdll.dll!KiUserCallbackDispatcherContinue() Unknown
user32.dll!NtUserPeekMessage() Unknown
user32.dll!PeekMessageW() Unknown
...
I found that somewhat interesting, because I'm assuming the method at the top copies data from my input structure into an internal structure and something goes wrong. But what's wrong with my input data structure?
The source code itself is available on GitHub at: https://github.com/oliversalzburg/ie-button