Click here to Skip to main content
15,922,894 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to register a dll ?? Pin
Sarvesvara (BVKS) Dasa20-Dec-03 2:37
Sarvesvara (BVKS) Dasa20-Dec-03 2:37 
GeneralMFC app Pin
nukenuts20-Dec-03 0:45
nukenuts20-Dec-03 0:45 
GeneralRe: MFC app Pin
Monty220-Dec-03 0:54
Monty220-Dec-03 0:54 
GeneralRe: MFC app Pin
nukenuts20-Dec-03 10:47
nukenuts20-Dec-03 10:47 
GeneralRe: MFC app Pin
Monty220-Dec-03 19:36
Monty220-Dec-03 19:36 
GeneralRe: MFC app Pin
nukenuts20-Dec-03 22:58
nukenuts20-Dec-03 22:58 
GeneralRe: MFC app Pin
Roger Allen22-Dec-03 1:15
Roger Allen22-Dec-03 1:15 
GeneralCreateProcess or multiple spawns problem under Windows 95, 98 ME (IN DESPERATE NEED!! Pin
Anonymous20-Dec-03 0:04
Anonymous20-Dec-03 0:04 
Hello to anyone who is willing to put a little thought in this.
I am in a quite hopless position right now.

The problem is this:
Suppose that there is a program that is running under Windows 95, 98 or ME, and this program malfunctions and freezes at some point. An external process (another program), learns this (
via means of a common bit in the LPT1, or a memory location being written periodically with '1' or '0' , so that the 'external watchdog program' gets the changes and knows if the program is still alive or not).

This, under Microsoft C++, would naturally involve CreateProcess or ShellExecute API calls to spawn the process and TerminateProcess to kill it. The problem is that under testing, when I terminate and re-spawn the process at regular 20s. intervals, after a while (it may be a few minutes up to half an hour, i.e. from 10 - 200 re-spawns), I get the Pop-Up Window

"Windows cannot find xxx.xxx. Please make sure the file exists e.t.c."

The weird thing is that CreateProcess API returns succesfully
and the GetLastError function is equal to 0, i.e. no error!

This happens when I run my code under Windows 95, 98 or ME.
Under Windows XP and for 12 hours consecutivelly the program runs fine. What could be the issue here?

**Note that both processes are console applications.**

I also tried putting a significantly long wait between the kill and the re-spawning (e.g. 13 seconds) but to no avail.

Something gets corrupted at some point but I have not been able to trace what. I do not think memory leaks is an issue in this case as the program is fairly simplistic and I close all handles normally.

I post some sample code below:

#include "stdafx.h"
#include "GetProcessID.h"
#include <tlhelp32.h>
#include <conio.h>

#define Debug true

unsigned char bit;

void killTheOther();
void RebootTheOther();
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo = {0};
HANDLE theHandle;

int main(int argc, char* argv[])
{
UINT nactual = 0;
unsigned char temp = '0';
int SetWaiting = 0;
SetConsoleTitle("Stupid");
HANDLE Done = CreateEvent(0, FALSE, FALSE, 0);
// ensure window title has been updated
// look for newWindowTitle
Sleep(40);
HWND hwndFound = FindWindow(NULL, "Stupid");
// If found, hide it
if ( hwndFound != NULL){
//ShowWindow( hwndFound, SW_HIDE);
}
CloseHandle(hwndFound);
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_SHOW;
if (!(CreateProcess("C:\\2.exe", NULL, NULL, NULL, FALSE,
CREATE_SUSPENDED | CREATE_NEW_CONSOLE, NULL, NULL,
&StartupInfo, &ProcessInfo))){
printf("Could not start process..., beacause:%d \n",
GetLastError());
theHandle =NULL;
}
else {
ResumeThread(ProcessInfo.hThread);
if (Debug)
printf("Process is started...\n");
theHandle = ProcessInfo.hProcess;
}
while(true){
bit = '0';
temp = bit;
if (Debug)
printf("Checking status...\n");
if (temp == bit){
SetWaiting++;
}
else{
SetWaiting = 0;
}
if (SetWaiting > 2){
printf("Here...\n");
if(theHandle != NULL){
killTheOther();
Sleep(10000);
RebootTheOther();
}
else{
printf("The han is NULL\n");
}
SetWaiting = 0;
}
WaitForSingleObject(Done, 10000);

}
return 0;
}

void killTheOther(){
TerminateProcess(theHandle, 0);
CloseHandle(theHandle);
theHandle = NULL;
}

void RebootTheOther(){
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
if (!(CreateProcess("C:\\2.exe", NULL, NULL, NULL,
FALSE, CREATE_SUSPENDED |
CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo,
&ProcessInfo))){
if (Debug)
printf("Could not start process...\n");
theHandle = NULL;
}
else {
ResumeThread(ProcessInfo.hThread);
if (Debug)
printf("Process is started...\n");
theHandle = ProcessInfo.hProcess;
}
}

Sorry about my English
GeneralRe: CreateProcess or multiple spawns problem under Windows 95, 98 ME (IN DESPERATE NEED!! Pin
Monty220-Dec-03 0:15
Monty220-Dec-03 0:15 
GeneralRe: CreateProcess or multiple spawns problem under Windows 95, 98 ME (IN DESPERATE NEED!! Pin
Anonymous20-Dec-03 1:12
Anonymous20-Dec-03 1:12 
GeneralRe: CreateProcess or multiple spawns problem under Windows 95, 98 ME (IN DESPERATE NEED!! Pin
Monty220-Dec-03 1:42
Monty220-Dec-03 1:42 
GeneralRe: CreateProcess or multiple spawns problem under Windows 95, 98 ME (IN DESPERATE NEED!! Pin
Anonymous20-Dec-03 1:58
Anonymous20-Dec-03 1:58 
Generaluser name password prob. in win2000 professional Pin
skpanda19-Dec-03 22:02
skpanda19-Dec-03 22:02 
GeneralRe: user name password prob. in win2000 professional Pin
l a u r e n20-Dec-03 6:27
l a u r e n20-Dec-03 6:27 
GeneralInternal error during ReadSymbolTable Pin
Balkrishna Talele19-Dec-03 19:50
Balkrishna Talele19-Dec-03 19:50 
GeneralRe: Internal error during ReadSymbolTable Pin
Monty220-Dec-03 0:49
Monty220-Dec-03 0:49 
GeneralRe: Internal error during ReadSymbolTable Pin
Balkrishna Talele20-Dec-03 0:52
Balkrishna Talele20-Dec-03 0:52 
GeneralRe: Internal error during ReadSymbolTable Pin
Monty220-Dec-03 1:03
Monty220-Dec-03 1:03 
GeneralRe: Internal error during ReadSymbolTable Pin
Balkrishna Talele20-Dec-03 1:08
Balkrishna Talele20-Dec-03 1:08 
GeneralRe: Internal error during ReadSymbolTable Pin
Daren Church16-Mar-11 2:12
Daren Church16-Mar-11 2:12 
GeneralRe: Internal error during ReadSymbolTable Pin
Balkrishna Talele16-Mar-11 20:51
Balkrishna Talele16-Mar-11 20:51 
QuestionHow to give the log on as a service right to a user thru program in WINDOWS-XP? Pin
renjithak19-Dec-03 19:37
renjithak19-Dec-03 19:37 
AnswerRe: Nobody to answer this ?? !!!!!! Pin
renjithak21-Dec-03 17:43
renjithak21-Dec-03 17:43 
GeneralBitmap image in IE toolbar... :) Pin
Vermithrax19-Dec-03 14:44
Vermithrax19-Dec-03 14:44 
GeneralRe: Bitmap image in IE toolbar... :) Pin
Shog919-Dec-03 17:11
sitebuilderShog919-Dec-03 17:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.