Visual C++ is reporting that an invalid parameter was passed to fclose
, that parameter being the FILE*
returned by freopen_s:
#include <WinSock2.h>
#include <iostream>
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(nCmdShow);
#ifdef _DEBUG
AllocConsole();
#else
AttachConsole(ATTACH_PARENT_PROCESS);
#endif
FILE* pCout;
freopen_s(&pCout, "conout$", "w", stdout); //returns 0
fclose(pCout);
#ifdef _DEBUG
system("pause");
#endif
FreeConsole();
return 0;
}
Should I not attempt to close conout$ at the end of the program? Is the exception being thrown because the file pointer is shared between processes for all console output?