Using TerminateProcess()on a 16 Bit application

I have an installation program that is written in win32 that needs to call a bunch of old win16 programs that will actually do the installation.  

I would like to give the user the ability to abort the intallation process as these win16 programs have been known to lock up.  But if I call TerminateProccess() on the 16 bit process handle it does not termiante the proccess.  The TerminateProccess Prcedure returns 0--indicating an error occured and GetLastError() returns 6--indicating that the handle is invalid.

However the handle is not invalid.  If I replace the 16 bit program EXEs with 32 bit "dummy" EXEs, then I can kill the 32 bit process fine (with the identical code--no need to even recompile.)  

Why can't I kill the 19 bit processes and is there a way to do so?

This was tested under NT only.  It needs to work in NT, 98, and 95.
LVL 22
nietodAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
OK - glad it worked ;-)
0
 
MadshiCommented:
I'm using TerminateProcess to terminate 16bit application. But I'm doing it with win95/98. And, I'm using toolhelp functions to find a process called "winoa386".
So please try your solution on win95. If it doesn't work there - you'll have the wrong handle. Don't know why. Then please use toolhelp functions (or for NT use "psapi.dll")...

Regards, Madshi.
0
 
jkrCommented:
On NT, the best choice would be to terminate NTVDM.EXE - but as this also would kill all other 16bit apps, it is useless...
But what about spawning a 16bit 'terminator' that uses the good (?) ol' 16bit 'EnumTaskWindows()', 'IsTask()' and 'TerminateApp()' Win16 APIs (all you have to make sure is specifying 'CREATE_SHARED_VDM' whan calling 'CreateProcess()')? Just an idea...
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
nietodAuthor Commented:
Well this is for legacy stuff, so I'm not going to put too much work into it.  (And I don't even know if I could create a 16 bit app anymore.)  Do you know for sure that simple means like TerminateProcess() won't work?  (If so, answer and I'll call it quits, I'm not loosing sleep over this.)
0
 
MadshiCommented:
With Win95/98, TerminateProcess works (at least, if you have the right handle).
I don't know how it is with NT. I've something in mind that you can enumerate the dos processes with "psapi.dll", too. But I'm not so sure about it. However, I think, there are 32bit apis for this purpose in NT.
0
 
jkrCommented:
nietod, at least for NT there's a suitable solution for you (see, i'm a curious guy ;-)

/*
 *  compile: cl kill16.cpp /link kernel32.lib
 */

#include <windows.h>
#include <stdio.h>

long    main    (   int     argc,
                    char**  argv
                )
{
    BOOL                bRes;

    STARTUPINFO         si;
    PROCESS_INFORMATION pi;
    HANDLE              hProcess;

    ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

    si.cb   =   sizeof  (   STARTUPINFO);

    bRes    =   CreateProcess   (   NULL,
                                    "h:\\programs\\mahjongg\\mjwin.exe",
                                    NULL,
                                    NULL,
                                    FALSE,
                                    NORMAL_PRIORITY_CLASS | CREATE_SEPARATE_WOW_VDM,
                                    NULL,
                                    "h:\\programs\\mahjongg",
                                    &si,
                                    &pi
                                );

    if  (   bRes)
        {
            printf  (   "PH:0x%.8x TH:0x%.8x PID:%d TID:%d\n",
                        pi.hProcess,
                        pi.hThread,
                        pi.dwProcessId,
                        pi.dwThreadId
                    );

            Sleep   (   5000);

            if  (   !TerminateProcess   (   pi.hProcess,    0))
                {
                    printf  (   "Error:%d\n",   GetLastError    ());
                }
        }
     else   printf  (   "\n\tERROR creating process: %d\n\n",  
                        GetLastError    ()
                    );

    return  (   0);
}

NOTE that 'CREATE_SEPARATE_WOW_VDM' apparenty did the trick...

(well, found no other 16bit app than 'mahjongg' <lol>)
0
 
nietodAuthor Commented:
Great.  I will try that in an hour or two.  If it works (it should) I'll let know know...
0
 
jkrCommented:
And - does it work (well, it should...) ?
0
 
nietodAuthor Commented:
By an hour or two, I meant a programmer's hour or two.  I'll let you know by march...
0
 
jkrCommented:
;-)
Fine - take you time, i'll leave for home now anyway ( it's almost 10pm here, which is late even for me <s>)
0
 
nietodAuthor Commented:
jkr, that did the trick!.  And look it only took me 5 (programmer) minutes to test it.

answer away
0
 
nietodAuthor Commented:
Adjusted points to 75
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.