redirect i/o

Discussion in 'MFC' started by goT, Jun 19, 2006.

  1. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    my mfc app calls a dll (open source) that sends strings to standard out (cout). How to redirect that to my mfc app during runtime?.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    There more than one option to do this.

    1. They should provide an option of sending the output to some other window apart from console.
    2. You should edit the necessary function to have the same functionality as its open source.
    3. You write your own dll to to send the output to your program.
     
  3. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    it is a c++ dll (must keep it c++ dll). Not windows dll. its has a class member, int m_counter;
    Code:
    void CUpCalss::Func()
    {
    for (,,)
    m_counter++;
    i like this m_counter get updated in edit control of my mfc gui.
    }
    I am not sure how to implement this.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    There are lots of ways you can do this.

    1. You write the class with _declspec(dllexport) option and you can directly import the class from where the GUI is located.
    2. Pass the handler to the edit box where the DLL class can display the output.
     
  5. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    i don't get it. if i am calling Func(), then how my mfc app can access m_counter while Func() is running?.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Check out [thread=907]Creating a simple DLL[/thread] article. That will help you to get things moving.
     
  7. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include "dll.h"
    void CDll::ATestMethod()
    {
    	m_c = 0;
    	for (int i = 0; i<1000; i++)
    		m_c++;		
    	
    }
    can you make the exe app or any other app to show the m_c increment?. i'll keep trying. Specailly in an mfc application.
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Pass the handle to the window to the method ATestMethod() where you want to display the data and set the data from method using the handle
     
  9. goT

    goT New Member

    Joined:
    Jan 3, 2006
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    can you show me in actual code if i am not asking too much?.
     
  10. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Download the code from the above article and add a new function to the DLL
    Code:
    void CDll::ATestMethod(HWND hwnd)
    {
    	CWnd *editbox = CWnd::FromHandle(hwnd);
    	editbox->SetWindowText("Shabbir");
    }
    Now call this method from a dailog based MFC app using the following
    Code:
    	CDll dll;
    	dll.ATestMethod(m_edt.GetSafeHwnd());
    Assuming m_edt is the DDX_Control of the edit box. If you dont get it let me know your email and I will mail the code to you.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice