'Encountered an improper argument.'
11 March, 2013
Ever run into this error message?
The error message 'Encountered an improper argument.' is from an uncaught exception in WindowProc.
In:
LRESULT CWinApp::ProcessWndProcException(CException* e, const MSG* pMsg)
e->ReportError(MB_ICONEXCLAMATION|MB_SYSTEMMODAL, nIDP);
the error message is nIDP = AFX_IDP_INTERNAL_FAILURE
:
#define AFX_IDP_INTERNAL_FAILURE 0xF108 // general failure
Usually you don't end up here. But there are cases where it happens. I have one example which was difficult to debug: An existing MFC based app upgraded to a ribbon control using a release build with static linking. Dynamic linked release builds and all debug builds are not affected.
It all starts at the InitInstance()
of your app when you load the main frame:
pFrame->LoadFrame(IDR_MAINFRAME,
WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,
NULL);
Then all the way down the call stack:
BOOL CFrameWndEx::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
BOOL CFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
CWnd* pParentWnd, CCreateContext* pContext)
BOOL CFrameWnd::Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
LPCTSTR lpszMenuName,
DWORD dwExStyle,
CCreateContext* pContext)
BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
until you reach:
ISOLATION_AWARE_INLINE HWND IsolationAwarePrivatenCv IsolationAwareCreateWindowExW(_In_ DWORD dwExStyle,_In_opt_ LPCWSTR lpClassName,_In_opt_ LPCWSTR lpWindowName,_In_ DWORD dwStyle,_In_ int X,_In_ int Y,_In_ int nWidth,_In_ int nHeight,_In_opt_ HWND hWndParent,_In_opt_ HMENU hMenu,_In_opt_ HINSTANCE hInstance,_In_opt_ LPVOID lpParam)
At this point you suddenly end up in the exception handler of the WndProc:
LRESULT AFXAPI AfxCallWndProc(CWnd* pWnd, HWND hWnd, UINT nMsg,
WPARAM wParam = 0, LPARAM lParam = 0)
All class names, handles and sizes look alright. The last message is 5, which is a WM_SIZE message with the right lParam value. Usually you get a debug break and know why the exception was raised, but here it seemed a mystery. But a quick compare to a sample app from the templates revealed the solution: The ribbon required additional resources in order to run in a static release build in the .rc file:
#if !defined(_AFXDLL)
#include "l.DEU\afxprint.rc" // Ressourcen für Drucken/Seitenansicht
#include "l.DEU\afxribbon.rc" // Ressourcen für MFC-Menüband und -Steuerleiste
#endif
(Remove the language prefix 'l.DEU\' with your language code if you are building another language.)