Writing to a Windows console

This is a discussion on Writing to a Windows console within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have a dll which is called by an application I have no control over. It loads my dll ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    3

    Writing to a Windows console

    Hi,
    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:

    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
    Location
    Canada
    Posts
    8,048
    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.
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    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, 04:13 PM
  2. windows console probs
    By henroid815 in forum C++ Programming
    Replies: 3
    Last Post: 05-05-2003, 04:36 AM
  3. windows console code probs
    By henroid815 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2003, 06:53 PM
  4. multiple console windows
    By gordy in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-13-2002, 11:05 PM
  5. windows dos console
    By dune911 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-16-2002, 11:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21