A macro LogTxt is defined as follows:
#define LogTxt(...) \
BOOL bRet1 = SetEvent(hEvt); \
ATLTRACE(__VA_ARGS__)
In the middle of a source, LogTxt use GetLastError as an argument.
...
HANDLE hEvt;
HWND hWnd;
BOOL bRet2 = ShowWindow(hWnd, 1);
LogTxt("GetLastError=%d", GetLastError());
...
I am expecting LogTxt prints the error number for ShowWindow, but the result is the error number for SetEvent.
__VA_ARGS_ macro is not safe to use with GetLastError as an argument.
What I have tried:
I tried
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
{
HANDLE hEvt;
HWND hWnd;
BOOL bRet2 = ShowWindow(hWnd, 1);
LogTxt("GetLastError=%d", GetLastError());
return 0;
}
and the expected result was 1400, but the actual result was 6
GetLastError=6
=> So, __VA_ARGS__ is not safe to use GetLastError as an argument.