Category : C++ Source Code
Archive   : EXECWA.ZIP
Filename : EXECWAIT.CPP

 
Output of file : EXECWAIT.CPP contained in archive : EXECWA.ZIP
#include "ExecWait.h"
#include
HTASK ExecWait::hWndNotify = NULL;
HTASK ExecWait::htSpawned = NULL;
//============================================================================
// Contstructor
// Register our notify procedure, then spawn the application, then obtain its
// task handle and return to the caller.
//============================================================================
ExecWait::ExecWait(HWND hWnd, HINSTANCE hInst, LPCSTR szCmdLine)
{
lpNotifyProc = (LPFNNOTIFYCALLBACK)
MakeProcInstance((FARPROC)ExecWait::NotifyProc, hInst);
nErr = NotifyRegister(GetCurrentTask(), lpNotifyProc, NF_NORMAL);
if (!nErr)
{
nErr = EXEC_ERR_REGISTRATION;
bRegistered = FALSE;
return;
}
hWndNotify = hWnd;
bRegistered = TRUE;

nErr = WinExec(szCmdLine, SW_SHOW);
if (nErr < 32)
{
nErr = EXEC_ERR_WINEXEC - nErr;
return;
}
htSpawned = GetTaskHandle((HINSTANCE)nErr);
if (!htSpawned)
{
nErr = EXEC_ERR_NOTASK;
return;
}
nErr = 0;
}
//============================================================================
// Destructor
// Deregister us and free the proc instance, If smart callbacks were used
// Free Proc instance would not be necessary but you would need to export the
// window porcedure that the notify proc wishes to post a message to.
//============================================================================
ExecWait::~ExecWait(void)
{
if (bRegistered)
NotifyUnRegister(GetCurrentTask());
FreeProcInstance((FARPROC)lpNotifyProc);
hWndNotify = NULL;
htSpawned = NULL;
}
//============================================================================
// GetTaskHandle
// This slowly walks the task list to find which task we spawned based upon
// the instance that was returned by the WinExec call
//============================================================================
HTASK ExecWait::GetTaskHandle(HINSTANCE hInst)
{
TASKENTRY te;
BOOL bMore;

te.dwSize = sizeof(te);
bMore = TaskFirst(&te);
while (bMore)
{
if (te.hInst == hInst)
return te.hTask;
else
bMore = TaskNext(&te);
}
return NULL;
}
//============================================================================
// NotifyProc
// We are registered to get notifications when we get an exit notification
// If it is the task that we spawned then post a message to the window
//============================================================================
BOOL _export CALLBACK ExecWait::NotifyProc(WORD wId, DWORD dwData)
{
if (wId == NFY_EXITTASK && GetCurrentTask() == htSpawned)
PostMessage(hWndNotify, WM_TASK_QUIT, LOBYTE(dwData), NULL);
return FALSE;
}


  3 Responses to “Category : C++ Source Code
Archive   : EXECWA.ZIP
Filename : EXECWAIT.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/