Prev: Calling TerminateThread() from the thread itself?
Next: Using an OCX class from a non-MFC, non-GUI app?
From: Larry on 12 Feb 2010 11:56 Hi, I would like to create custom macro (and methods) in order to deal with message sent from the menu, so far I have coded the following: #define STRICT #include <windows.h> #include <windowsx.h> #define IDM_BLOCK 800 // Declare Custom HANDLE MSG // #define HANDLE_IDM_BLOCK(hwnd, wParam, lParam, fn) \ ((fn)(hwnd), 0L) #define FORWARD_IDM_BLOCK(hwnd, fn) \ (void)(fn)((hwnd), IDM_BLOCK, 0L, 0L) /////////////////////////////// // Default void Cls_OnDestroy(HWND hwnd); void Cls_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify); BOOL Cls_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct); // Custom void Cls_OnMenuBlock(HWND hwnd); LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { __try { switch (message) { HANDLE_MSG (hWnd, WM_CREATE, Cls_OnCreate); HANDLE_MSG (hWnd, WM_COMMAND, Cls_OnCommand); HANDLE_MSG (hWnd, WM_DESTROY, Cls_OnDestroy); } } __except(EXCEPTION_EXECUTE_HANDLER) {} return DefWindowProc(hWnd, message, wParam, lParam); } void Cls_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify) { __try { switch (id) { HANDLE_MSG (hWnd, IDM_BLOCK, Cls_OnMenuBlock); } } __except(EXCEPTION_EXECUTE_HANDLER) {} } void Cls_OnMenuBlock(HWND hwnd) { } Now, when I run the code I get this error: error C2562: 'Cls_OnCommand' : 'void' function returning a value I don't see that function returns any value as opposite to the error fired by the compiler... what am I doing wrong? I just need functions like this: Cls_OnMenuBlock(HWND hwnd); to take along only the HWND thanks
From: Igor Tandetnik on 12 Feb 2010 12:23
Larry <dontmewithme(a)got.it> wrote: > // Declare Custom HANDLE MSG // > #define HANDLE_IDM_BLOCK(hwnd, wParam, lParam, fn) \ > ((fn)(hwnd), 0L) > > void Cls_OnCommand(HWND hWnd, int id, HWND hwndCtl, UINT codeNotify) > { > __try > { > switch (id) > { > HANDLE_MSG (hWnd, IDM_BLOCK, Cls_OnMenuBlock); > } > } > __except(EXCEPTION_EXECUTE_HANDLER) {} > } > > Now, when I run the code I get this error: error C2562: > 'Cls_OnCommand' : 'void' function returning a value HANDLE_MSG is defined this way in windowsx.h: #define HANDLE_MSG(hwnd, message, fn) \ case (message): return HANDLE_##message((hwnd), (wParam), (lParam), (fn)) Thus, your function, despite being declared void, contains "return some_expression;" statement. > I don't see that function returns any value as opposite to the error > fired by the compiler... HANDLE_IDM_BLOCK expands to (something, 0L). This is an expression with a value of 0L. So basically you are doing case IDM_BLOCK: something; return 0L; This return statement is illegal in a function with a return type of void. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925 |