Our application automatically starts several sessions when the application starts, using command line:

Attachmate.Emulation.Frame.exe" -f "RIBM3270.rd3x" -ipcname K -uimode classic -N
Attachmate.Emulation.Frame.exe" -f "RIBM3270.rd3x" -ipcname L -uimode classic -N

This automatically starts a K and L session.

The application is a non-.NET application. It is pure Win32.

To control the sessions we use HLLAPI to connect and interact with the sessions.

The issue we have is when our application closes, it should automatically close the sessions. The session windows and processes must be closed.

We could not find a way using somekind of API to do this. Maybe there is a command line switch to close a particular session, but could not find such an option.

So we implemented this:

We know the window title of each started session.
Using WInAPI we get the window handle and send a WM_CLOSE to it.

This seems to work, but only when there are no other windows open in the session. When a error msgbox is displayed in the session, the close does not work.
So we get all opened windows within the session, find error msgboxes and WM_CLOSe them. Afterwards we send WM_CLOSE to the main session window.

BUt this is really not efficient and prone to errors.
When the session is starting for example, the title is not yet set to the window.
Also the title could be changed, which breaks this implementation.

What would be the best way for us to achieve the need to close sessions?

Be aware that we do not have a .NET application. We can use ActiveX/COM, but not .NET assemblies directly.

Any hint or tip is appreciated.

Best regards,