I’m writing an application hat will use the same form defaults on most of the forms, so i decided to macro the WNDClASSEX and call it when needed:
#pragma once
#ifndef WNDCLASSEX_H
#define WNDCLASSEX_H
#include <windows.h>
//MAIN FORM / LOADER WNDCLASSEX
#define MainLoaderWnd(Size, WindowsProcess, hInstance, Title)\
{\
return new WNDCLASSEX{\
size,\
CS_DBLCLKS,\
WindowsProcess,\
0,\
0,\
hInstance,\
LoadIcon(NULL, IDI_APPLICATION),\
LoadCursor(NULL, IDC_ARROW),\
(HBRUSH)(COLOR_WINDOW),\
NULL,\
L(Title),\
LoadIcon(NULL, IDI_APPLICATION)\
};\
}
#endif
however, when i add this into the file “loader.cpp”, i get the following:
WNDCLASSEX wcex = MainLoaderWnd(sizeof(WNDCLASSEX), WndProc, hInstance, L"Your Text Here");
//Intellisense error: Expression Expected
Ideas/ can’t see why his error occurs. :/
A preprocessor macro is not a function. What the preprocessor does when it sees
MainLoaderWndbeing “called” in your code is to replace the “call” with the text in the macro body. This means you assignment will look like this:This is not a valid assignment.
Instead you could create an
inlinefunction, which is like a proper function but the compiler (not the preprocessor) may put the generated code inline at the place of the call: