Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   redirect i/o (http://www.go4expert.com/forums/redirect-i-o-t905/)

goT 19Jun2006 09:33

redirect i/o
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?.

shabbir 19Jun2006 10:11

Re: redirect i/o
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.

goT 19Jun2006 11:50

Re: redirect i/o
it is a c++ dll (must keep it c++ dll). Not windows dll. its has a class member, int m_counter;

void CUpCalss::Func()
for (,,)
i like this m_counter get updated in edit control of my mfc gui.

I am not sure how to implement this.

shabbir 19Jun2006 12:43

Re: redirect i/o
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.

goT 19Jun2006 15:26

Re: redirect i/o
i don't get it. if i am calling Func(), then how my mfc app can access m_counter while Func() is running?.

shabbir 20Jun2006 10:53

Re: redirect i/o
Check out Creating a simple DLL article. That will help you to get things moving.

goT 20Jun2006 12:08

Re: redirect i/o

#include "dll.h"
void CDll::ATestMethod()
        m_c = 0;
        for (int i = 0; i<1000; i++)

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.

shabbir 20Jun2006 15:11

Re: redirect i/o

Originally Posted by goT
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.

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

goT 20Jun2006 16:07

Re: redirect i/o
can you show me in actual code if i am not asking too much?.

shabbir 20Jun2006 19:49

Re: redirect i/o
Download the code from the above article and add a new function to the DLL
Code: CPP

void CDll::ATestMethod(HWND hwnd)
    CWnd *editbox = CWnd::FromHandle(hwnd);

Now call this method from a dailog based MFC app using the following
Code: CPP

CDll dll;

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.

All times are GMT +5.5. The time now is 12:47.