Thread: Writing to a Windows console

  1. #1
    Registered User
    Join Date
    Feb 2008

    Writing to a Windows console

    I have a dll which is called by an application I have no control over. It loads my dll and calls the appropriate functions I've exported. I have logging to a file, but I would also like some console logging to view in real time as the app runs. So I have this in my code:

    double myfunction( const char* stuff)
    	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    	SetConsoleTitle("New Title");
    	char test[] = "writing....\n";
    	int x = WriteConsole(hConsole, test, lstrlen(test), &cChars, NULL);
    When my function is called, the main applications consoles title bar changes to "New Title" as I have specified. However, the bit of text I have written isn't coming up. I suspect the handle I have is wrong, can anyone help me here? Also, is there an easier API I can use? I thought printf would just write to the std output but that doesn't seem to work either. (which leads me to believe I'm writing to the wrong stream)

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    What does x contain? In other words, what did WriteConsole() return? A failure value? If so, what does GetLastError() say the error was?

    I suggest you read the page I linked to above; maybe something there will be of use.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. One process with two console windows
    By siavoshkc in forum Windows Programming
    Replies: 8
    Last Post: 01-30-2009, 03:13 PM
  2. windows console probs
    By henroid815 in forum C++ Programming
    Replies: 3
    Last Post: 05-05-2003, 03:36 AM
  3. windows console code probs
    By henroid815 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2003, 05:53 PM
  4. multiple console windows
    By gordy in forum A Brief History of
    Replies: 3
    Last Post: 02-13-2002, 10:05 PM
  5. windows dos console
    By dune911 in forum A Brief History of
    Replies: 2
    Last Post: 01-16-2002, 10:30 PM