Article ID: 153904
Article Last Modified on 10/23/2003
#include <windows.h>
#include <stdio.h>
HANDLE hInst;
HWND hDlg;
HANDLE hHeap;
BOOL APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID
lpReserved)
{
return 1;
UNREFERENCED_PARAMETER(hInst);
UNREFERENCED_PARAMETER(ul_reason_being_called);
UNREFERENCED_PARAMETER(lpReserved);
}
double APIENTRY backgrnd(void)
{
PROCESS_INFORMATION pInfo;
STARTUPINFO sInfo;
DWORD exitCode;
sInfo.cb = sizeof(STARTUPINFO);
sInfo.lpReserved = NULL;
sInfo.lpReserved2 = NULL;
sInfo.cbReserved2 = 0;
sInfo.lpDesktop = NULL;
sInfo.lpTitle = NULL;
sInfo.dwFlags = 0;
sInfo.dwX = 0;
sInfo.dwY = 0;
sInfo.dwFillAttribute = 0;
sInfo.wShowWindow = SW_SHOW;
// The path to notepad.exe in this example is for
// Windows NT. Your path may be different.
if (!CreateProcess("c:\\winnt351\\system32\\notepad.exe",
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&sInfo,
&pInfo)) {
printf("ERROR: Cannot launch child process\n");
exit(1);
}
// Give the process time to execute and finish
WaitForSingleObject(pInfo.hProcess, 50L);
return pInfo.dwProcessId;
}
#include <windows.h>
#include <stdio.h>
HANDLE hInst;
HWND hDlg;
HANDLE hHeap;
BOOL APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID
lpReserved)
{
return 1;
UNREFERENCED_PARAMETER(hInst);
UNREFERENCED_PARAMETER(ul_reason_being_called);
UNREFERENCED_PARAMETER(lpReserved);
}
void APIENTRY terminat(double processid)
{
//PROCESS_INFORMATION pInfo;
DWORD exitCode;
HANDLE fhandle;
fhandle = OpenProcess(PROCESS_ALL_ACCESS, TRUE, (DWORD)processid);
if (GetExitCodeProcess(fhandle, &exitCode))
{
switch(exitCode)
{
case STILL_ACTIVE: printf("Process is still active\n");
break;
default: printf("Exit code = %d\n", exitCode);
break;
}
}
else {
printf("GetExitCodeProcess() failed\n");
}
BOOL TermSucc;
TermSucc= TerminateProcess(fhandle, exitCode);
if (TermSucc == FALSE)
printf("TerminateProcess");
else
printf("Process terminated successfully!\n");
}
PUBLIC DOUBLE phandle
phandle = 0
DECLARE DOUBLE backgrnd IN c:\BACKGRND.DLL
phandle = backgrnd()
WAIT WINDOW("Note Pad is now Running")
DECLARE terminat IN c:\TERMINAT.DLL DOUBLE
FoxHWND = terminat(phandle)
Additional query words: VFoxWin
Keywords: KB153904