Fog Creek Software
g
Discussion Board




Hook into Win32 "Terminal" App

Hello!

At work, we're using some app that "emulates" an old DOS-like terminal. All transactions with the end "systems" is done via entering commands and text strings.

This ofcourse gets pretty tedious and repetetive. It does have a macro system, but it's far too limited to be of real practical use.

So, I snagged a copy of this terminal app (it's a Win32 app, by the way) home, and figured I'd try to hook into the app, so I could create a separate GUI app that can send and retrieves data from the Terminal app.

Has anyone of you done something similar before? In which case, can you recommend where and how to start?

Thanks for any ideas!

Rootbert
Wednesday, October 22, 2003

I'm a bit confused by what you're describing.

If this is a Windows App that's just emulating a terminal plugged into another system, then it should be pretty easy. I've written several apps that interact with host applications by pretending to enter commands. Most terminal programs have an API layer to do this - what terminal app are you using, and what terminal is it emulating?

OTOH, if you have a stand alone console application, it might be possible to do it by executing the app from within your GUI application with the stdin/stdout files redirected to ones that your program can access.

RocketJeff
Wednesday, October 22, 2003

Okay. Imagine you have a hotel booking reservation system based on sending strings of text to a server, then getting a response. This is what it's about - once upon a time all these transactions were done by a simple terminal.

Then the company moved on to Windows, and thus needed the terminal there - so they wrote an in-house win32 app that functions like a terminal, in a window. It doesn't work like a DOS window, but a normal Win32 window. I'm not sure how they did the text i/o - I bet it's something custom, since you can select different keyboard layouts within the app (as with macros)

How would I go about sending "key-presses" to a Win32 app? And how can I poll it for the responses?

Thanks!

Rootbert
Wednesday, October 22, 2003

Can you hook in at a 'lower' level? (e.g. if this is a real terminal emulator, just talk straight to the server)? Or do you just want to add macros?

I wish there were a general win32 macro program, anyone know of one? Like the ancient MacroRecorder on the mac (and a similar tool someone wrote for OSX).

Anyway, you'll have to learn about windows messages to this this yourself. Find the window, then send WM_CHAR messages to it. Read the response with WM_GETTEXT, etc. Spy++ is helpful.

mb
Wednesday, October 22, 2003

Maybe WinBatch.  We used it years ago to automate a bunch of little programs that needed repeated fiddling with.

You can find it at http://www.winbatch.com

Steve Barbour
Wednesday, October 22, 2003

Sounds like they wrote a simple terminal emulator taking to something like a Unix box. How is the connection made, over a serial cable or a network connection?

If it's over a serial line, just try closing the terminal app and opening Hyperterminal on the same serial port.  It should be an easy job to hack together a somple GUI that talks to a serial port.

If it's a network connection, just run telnet and connect to the same port that the app connect to. Again, simple to emulate from a GUI program.

Since you said that it's an in-house program, look at the code to see how they make the connection. I've done similar things in the past and it's not that difficult.

RocketJeff
Wednesday, October 22, 2003

I'd second the recommendation to learn what protocol is being spoken between the existing terminal application and the back-end system, and to look at writing a replacement.

If the existing terminal application does more than act like a dumb terminal, then either acquire its source code, or hook up a line analyzer on the connection to the back end server. You haven't said what the physical connection is - if it's serial Rs-232 you will need a line analyzer; if it's a LAN you can find and download a common network spy application to list the packet traffic. In either event, you would be attempting to reverse-engineer whatever the terminal application "layers" on top of human typed commands.

What you're proposing - writing an application that acts as a surrogate keyboard user  by simulating the Windows messages for keystrokes - is *possible* - but in reality it would probably be a nightmare to get working correctly. It would work OK to enter strings to the emulator, but automation would require a *lot* of programming and debugging to intercept and operate on the returned responses. IMO, of course.

Bored Bystander
Wednesday, October 22, 2003

well there's always 'expect'

http://expect.nist.gov/

mb
Wednesday, October 22, 2003

You may play with WshShell object in JScript/VBScript to get one way automation of the program. As it pointed out above it would be near impossible to handle responces (especially error cases that happens once in a while)

Sample for using "calc.exe" on MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsMthSendKeys.asp

WildTiger
Wednesday, October 22, 2003

Ok, a bit more info towards the questions asked.

The terminal is a dumb app that communicates through another app, called a "sharer". The "sharer" does the real comm with the remote network databases (presumably heavy encryption and security measures, so I do not wish to 'hack' the "sharer").

It's a big firm with it's own IT department. I did pitch a mail to one of the devr's, and he said they're not updating the Term anymore. And unless my dept had a lot of money, it would not be improved.

I figured it should be easy enough to do a more user-friendly term. I do program C++, but have only done a small bit of Win32, and never used these "hooks".

But thanks for the leads, it'll be of great help!

Cheers!

Rootbert
Thursday, October 23, 2003

Ps. The "sharer" communicates via LAN/Intranet connection.

Rootbert
Thursday, October 23, 2003

It should be pretty easy then. If your corporate IS staff isn't going to support/upgrade the program anymore, just ask them for a copy of the source.

If that doesn't work, run your idea past your boss and see if he can leverage his position (or _his_ boss's position) to get you the source.

RocketJeff
Thursday, October 23, 2003

*  Recent Topics

*  Fog Creek Home