Click here to Skip to main content
15,891,828 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalfile system events Pin
sunil goyal23-Jul-02 21:49
sunil goyal23-Jul-02 21:49 
GeneralRe: file system events Pin
567890123423-Jul-02 22:47
567890123423-Jul-02 22:47 
GeneralAdd links to windows popup menus Pin
sunil goyal23-Jul-02 21:42
sunil goyal23-Jul-02 21:42 
GeneralRe: Add links to windows popup menus Pin
benjymous23-Jul-02 23:16
benjymous23-Jul-02 23:16 
GeneralConstructors - throw an exception if failed Pin
tom7623-Jul-02 21:36
tom7623-Jul-02 21:36 
GeneralRe: Constructors - throw an exception if failed Pin
Tomasz Sowinski24-Jul-02 1:09
Tomasz Sowinski24-Jul-02 1:09 
GeneralRe: Constructors - throw an exception if failed Pin
tom7624-Jul-02 1:45
tom7624-Jul-02 1:45 
GeneralRedirecting text to edit control Pin
Janine23-Jul-02 21:23
Janine23-Jul-02 21:23 
Hello,

I'm trying to redirect text, so that all text printed with printf would go to an edit control. I've seen a couple of examples (one by Microsoft and another by Codeguru) but those are done in a slightly different way.

What I want is to redirect text in my application, but those two examples use another application, whose printf commads they redirect. If I understood it right, an important thing in these applications is that they open a new window (well, sometimes they open it hidden) of the other application as the main application's child process.

Here's something that I've tried:
// Security attributes.
SECURITY_ATTRIBUTES sa;
::ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
sa.nLength= sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;

// Save the handle to the current STDOUT.
HANDLE hStdOutOld = GetStdHandle(STD_OUTPUT_HANDLE);

HANDLE hStdOutReadTmp;

// Create the child stdout pipe.
if ( !::CreatePipe(&hStdOutReadTmp, &m_hStdOut, &sa, 0) )
{
    MessageBox("Error: CreatePipe");
    return;
}

if( !::SetStdHandle(STD_OUTPUT_HANDLE, m_hStdOut) )
{
    ::CloseHandle( hStdOutReadTmp );
    ::CloseHandle( m_hStdOut );
    MessageBox("Error: SetStdHandle");
    return;
}

BOOL fSuccess = DuplicateHandle(GetCurrentProcess(), hStdOutReadTmp,
    GetCurrentProcess(), &m_hStdOutRead, 0, FALSE, DUPLICATE_SAME_ACCESS);

if ( !fSuccess )
{
    MessageBox("Error: DuplicateHandle");
    return;
}

CloseHandle(hStdOutReadTmp);


After this there should be the child process creation. But do I have to make it? There's also another thing that I don't understand: how do I connect the other end of the pipe to the edit control?

I tried to connect the edit control and stdout straight without a pipe like:
CEdit *pEdit = (CEdit*)(this->GetDlgItem(IDC_EDIT));
m_hStdOut = (HANDLE)pEdit->GetSafeHwnd();

if( !::SetStdHandle(STD_OUTPUT_HANDLE, m_hStdOut) )
{
    ::CloseHandle( m_hStdOut );
    MessageBox("Error: SetStdHandle");
    return;
}

The result is that nothing happens.

I also thought of doing it in the same way as in examples, but before creating windows. The problem is, that I have a console in the beginning (the starting point of this app is main() and in there the app is started using InitInstance() and Run()). If I understood those examples right all that creating pipes and so on needs to be done before creating windows. Does console count as a window?

What would be the best way to go?

-Janetta
GeneralRe: Redirecting text to edit control Pin
Christian Graus23-Jul-02 21:40
protectorChristian Graus23-Jul-02 21:40 
GeneralRe: Redirecting text to edit control Pin
Janine23-Jul-02 22:06
Janine23-Jul-02 22:06 
GeneralRe: Redirecting text to edit control Pin
Christian Graus23-Jul-02 22:25
protectorChristian Graus23-Jul-02 22:25 
GeneralRe: Redirecting text to edit control Pin
Janine24-Jul-02 0:01
Janine24-Jul-02 0:01 
GeneralRe: Redirecting text to edit control Pin
Christian Graus24-Jul-02 2:28
protectorChristian Graus24-Jul-02 2:28 
GeneralRe: Redirecting text to edit control Pin
Janine24-Jul-02 2:42
Janine24-Jul-02 2:42 
GeneralRe: Redirecting text to edit control Pin
Christian Graus24-Jul-02 2:45
protectorChristian Graus24-Jul-02 2:45 
GeneralRe: Redirecting text to edit control Pin
Janine24-Jul-02 3:05
Janine24-Jul-02 3:05 
GeneralRe: Redirecting text to edit control Pin
Christian Graus25-Jul-02 2:39
protectorChristian Graus25-Jul-02 2:39 
GeneralRe: Redirecting text to edit control Pin
Janine25-Jul-02 3:27
Janine25-Jul-02 3:27 
GeneralRe: Redirecting text to edit control Pin
Daniel Lohmann23-Jul-02 23:18
Daniel Lohmann23-Jul-02 23:18 
GeneralRe: Redirecting text to edit control Pin
Janine24-Jul-02 2:24
Janine24-Jul-02 2:24 
GeneralRe: Redirecting text to edit control Pin
Mandalay24-Jul-02 2:02
Mandalay24-Jul-02 2:02 
GeneralSpreadsheet Programming Pin
Anonymous23-Jul-02 20:37
Anonymous23-Jul-02 20:37 
GeneralRe: Spreadsheet Programming Pin
NormDroid23-Jul-02 22:18
professionalNormDroid23-Jul-02 22:18 
GeneralChange process security context Pin
Don Miguel23-Jul-02 20:35
Don Miguel23-Jul-02 20:35 
GeneralRe: Change process security context Pin
Daniel Lohmann23-Jul-02 23:23
Daniel Lohmann23-Jul-02 23:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.