redirect i/o

goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
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?.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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.
0
goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
i don't get it. if i am calling Func(), then how my mfc app can access m_counter while Func() is running?.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Check out Creating a simple DLL article. That will help you to get things moving.
0
goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
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.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
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
0
goT's Avatar, Join Date: Jan 2006
goT
Go4Expert Member
can you show me in actual code if i am not asking too much?.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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);
    editbox->SetWindowText("Shabbir");
}
Now call this method from a dailog based MFC app using the following
Code: CPP
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.