AllocConsole
-
When I use the WriteConsole method I always get a "First-chance exception in FileBinary.exe (KERNEL32.DLL): 0xC0000005: Access Violation." in the output window within Visual Studio, however the text that I sent in the WriteConsole method appears correctly on the console window. Does anyone know what I am doing wrong (I've attatched some sample code below which just sends an end of line to the console, AllocConsole has already been called elsewhere in my program)? LPDWORD s = 0 ; CString myStr = "\n" ; HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE ) ; WriteConsole ( h, myStr , myStr.GetLength ( ), s, NULL ) ; cheers, Andy
-
When I use the WriteConsole method I always get a "First-chance exception in FileBinary.exe (KERNEL32.DLL): 0xC0000005: Access Violation." in the output window within Visual Studio, however the text that I sent in the WriteConsole method appears correctly on the console window. Does anyone know what I am doing wrong (I've attatched some sample code below which just sends an end of line to the console, AllocConsole has already been called elsewhere in my program)? LPDWORD s = 0 ; CString myStr = "\n" ; HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE ) ; WriteConsole ( h, myStr , myStr.GetLength ( ), s, NULL ) ; cheers, Andy
LPDWORD is a pointer. You need to pass a valid memory location to the WriteConsole function, not just a random pointer. Also, cast the CString to a LPCTSTR manually, before turning it into a VOID*.
DWORD s = 0 ;
CString myStr = "\n";
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(h, (LPCTSTR)myStr, myStr.GetLength(), &s, NULL); -
LPDWORD is a pointer. You need to pass a valid memory location to the WriteConsole function, not just a random pointer. Also, cast the CString to a LPCTSTR manually, before turning it into a VOID*.
DWORD s = 0 ;
CString myStr = "\n";
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsole(h, (LPCTSTR)myStr, myStr.GetLength(), &s, NULL);