Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access to StdIn

Status
Not open for further replies.

turtlemaster

Programmer
Oct 4, 2001
93
0
0
US
I am writing an application that must communicate with an older application developed in C++ 4.0. I am not involved with the development on the C++ application but it is the main system currently in place now and cannot be modified much. I also do not get to pick the communication methods that our apps are to use. We are going to communicate via anonymous pipes which so far I think I will be able to figure out with the right API calls. CreatePipe, WriteFile and ReadFile. The problem lies with the initiation of the communication. The C++ app will be creating an instance of my app (using CreateProcess) and pass my app the hWrite handle to the pipe in StdIn. For the life of me I cannot figure out how to:

1.) get a handle to StdIn unless my app is a console app.
2.) read the data passed to me in stdin. (I assume I would used ReadFile)

Any direction would be greatly appreciated as administrator set a deadline of yesterday.

Thanks in advance.
 
It IS possible. Just do a keyword search in this forum. I have provided a fully worked example in the past on how to get VB to work properly with a console, and with STDIN, STDOUT and STDERR
 
Thanks strongm,

I read your example and although it is not exactly what I wan't to do its definently brough me closer to where I want to be. This application is going to launch an instance of my application and write something to Stdin. My trouble so far has been that I cannot access Stdin from VB. After reading your excellent tutorial I feel I needed to AllocConsole to get a Stdin and becuase it was launched from my app it should have inherited Stdin from my app (at least that is my understanding so far -- probably flawed). Before when I used GetStdHandle and 0 was returned becuase my app did not have a stdin, but after AllocConsole I now get a value. If I use SetStdHandle it returns a true value to both a read handle and a write handle of separate pipes I have created. As soon as I try to ReadFile or WriteFile to the pipe it blows up (crashes VB).

I tried to:

1.)create a pipe for reading stdin
2.)called AllocConsole
3.)Get handle to Stdin and saved for later
4.)Used DuplicateHandle to get hReadDup
5.)set stdin to hRead
6.)ReadFile using hReadDup

Though maybe you couldn't read from an empty pipe but writefile blew up too.

I noticed that you are launching the console app using create process to redirect the streams where as I can not. I am trying to ReadFile on my own StdIn not a child application.

Any other insight you may have would be great. Thanks Again!!
 
After more investigation I found this;


It is an exe that overwrites the header of your exe file and alllows you to intercept stdin of your app. This is what I wanted to do but I don't want my app to run inside of a console. It seems to me this is a limitation of the compiler.

I am going to try and convince the other party to send this information to my app using another method.
 
Wow - that's scarily close to my code for turning any VB6 app into a console application in thread222-339817

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top