Thread: Show printf's from dll

  1. #1
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168

    Show printf's from dll

    If i have printf("something"); in my DLL how do i make it appear to the screen?

    Ideally I would like the execution screen to appear, i would watch the printf's, then dissappear once th execution is finished.

    as of now i never see the execution screen

    im using MSVC6

    thanks for your help... this board is amazing.
    Last edited by chico1st; 08-29-2007 at 05:22 PM.

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    The printf function cannot be the dll. It should be in the stdio.h.

    Did you mean a different function such as user defined function which is named other than printf in the dll, which need to access in your main?

    ssharish2005

  3. #3
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    nonono
    i have a function that does a bunch of stuff but print to the screen during the execution of my dll.

    I want to see those prints to screen.

    right now i cant see my dll executing at all.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Most likely cause your dll doesn't have a console associated with it. Just because you are calling your dll from your code doesn't mean it has your console with it.

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Set the DLL's stdout and stdin handles (ie inherit them when you init the dll), to whatever and read it via a pipe. See MSDN

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    My guess is that you are using a DLL as part of a windows applicaiton, so there's no console attached to the application - is this correct? If so, you've got two choices:
    - replace printf's with fprintf's (and open a log-file at DLL init, close at DLL exit)
    - use AllocConsole() to create a console window (this does all the magic necessary to get printf working)

    For many things, the first approach is probably better than the second, as you get a permanent result. But if you want to see the progress for example, then the console window is a workable solution (but using a windows style progress is probably better).

    --
    Mats

  7. #7
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    hmmm.. the AllocConsole() is exactly what i want but it doesnt seem to work

    it brings up a console but it doesnt seem to write to it.

    my program is like this:
    Code:
    AllocConsole();
    
    Printf("blh blh");
    
    FreeConsole();
    
    OUTPUT:
    ________________
    |               |
    |               |
    |_______________|
    there is nothing in the console just a black screen.
    do I have to do some getConsolewindow() stuff?

  8. #8

  9. #9
    Wanabe Laser Engineer chico1st's Avatar
    Join Date
    Jul 2007
    Posts
    168
    sweet thanks man.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  4. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM
  5. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM