Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. program crushes!!

program crushes!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mpapeo
    wrote on last edited by
    #1

    I have a little menu here which i want to execute my functions using it. So i have problems in entering the process like notepad which i want to create, but then it crushes. How can i declare the variable which will take care of the input process, because i didn't want to include it in the commandline when running. Part of my code is below #include #include #include #include #include LPVOID lpMsgBuf; int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } int main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ LPDWORD lpExitCode = 0; HANDLE hProcess ; DWORD baseaddr = 0; DWORD error = GetLastError(); LPCTSTR lpApplicationName=""; int choice; menu(); while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ argv[1], /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, GetExitCodeProcess(hProcess,lpExitCode )); GetLastError(); break; default: printf("\nInvalid choice: "); }//while } return(0); } oam

    H 1 Reply Last reply
    0
    • M mpapeo

      I have a little menu here which i want to execute my functions using it. So i have problems in entering the process like notepad which i want to create, but then it crushes. How can i declare the variable which will take care of the input process, because i didn't want to include it in the commandline when running. Part of my code is below #include #include #include #include #include LPVOID lpMsgBuf; int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } int main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ LPDWORD lpExitCode = 0; HANDLE hProcess ; DWORD baseaddr = 0; DWORD error = GetLastError(); LPCTSTR lpApplicationName=""; int choice; menu(); while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ argv[1], /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, GetExitCodeProcess(hProcess,lpExitCode )); GetLastError(); break; default: printf("\nInvalid choice: "); }//while } return(0); } oam

      H Offline
      H Offline
      Hans Ruck
      wrote on last edited by
      #2

      Try this: #include "stdafx.h" #include <stdio.h> int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } void main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; TCHAR lpApplicationName[100]=""; int choice; while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ lpApplicationName, /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, 0); break; default: printf("\nInvalid choice: "); } } } And don't be as lazy as to believe anything you see...


      "though nothing  will keep us together  we can beat them  for ever and ever" rechi

      M 1 Reply Last reply
      0
      • H Hans Ruck

        Try this: #include "stdafx.h" #include <stdio.h> int menu(void) { int choice; printf ("\n"); printf ("*****************************************\n"); printf ("*\t\t\t\t\t*\n*\tCHECKPOINTING SYSTEM \t\t*\n"); printf ("========================================="); printf ("\n=\t 1: Create a process \t="); printf ("\n=\t 2: Shutdown the process\t="); printf ("\n=========================================\n"); printf ("\n"); printf("\nEnter choice (1-2): "); scanf("%d", &choice); return choice; } void main(int argc, char **argv) { PROCESS_INFORMATION pi ; /* filled in by CreateProcess */ STARTUPINFO si; /* startup info for the new process*/ HANDLE hProcess; TCHAR lpApplicationName[100]=""; int choice; while((choice = menu())!=3) { switch (choice) { case 1: printf("Enter process you want to execute: ",lpApplicationName); scanf ("%s",lpApplicationName); printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID GetStartupInfo(&si); CreateProcess(NULL, /* lpApplicationName */ lpApplicationName, /* lpCommandLine assumes to use curent process directory*/ NULL, /* lpsaProcess */ NULL, /* lpsaThread */ FALSE, /* bInheritHandles */ CREATE_NEW_CONSOLE, /* dwCreationFlags */ NULL, /* lpEnvironment */ NULL, /* lpCurDir */ &si, /* lpStartupInfo */ &pi /* lpProcInfo */ ); hProcess = pi.hProcess; printf("New Process ID: %d ",pi.dwProcessId); printf("has started \n"); break; case 2: TerminateProcess(pi.hProcess, 0); break; default: printf("\nInvalid choice: "); } } } And don't be as lazy as to believe anything you see...


        "though nothing  will keep us together  we can beat them  for ever and ever" rechi

        M Offline
        M Offline
        mpapeo
        wrote on last edited by
        #3

        Im sorry im using C language and now i'm having a problem with the header file stdafx.h because i think it works in C++. the error i'm getting shows this after adding the header file to the project. Compiling... pro.c c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(15) : fatal error C1189: #error : MFC requires C++ compilation (use a .cpp suffix) Error executing cl.exe. pro.obj - 1 error(s), 0 warning(s) oam

        H 1 Reply Last reply
        0
        • M mpapeo

          Im sorry im using C language and now i'm having a problem with the header file stdafx.h because i think it works in C++. the error i'm getting shows this after adding the header file to the project. Compiling... pro.c c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(15) : fatal error C1189: #error : MFC requires C++ compilation (use a .cpp suffix) Error executing cl.exe. pro.obj - 1 error(s), 0 warning(s) oam

          H Offline
          H Offline
          Hans Ruck
          wrote on last edited by
          #4

          Comment the #include "stdafx.h" line.


          "though nothing  will keep us together  we can beat them  for ever and ever" rechi

          M 1 Reply Last reply
          0
          • H Hans Ruck

            Comment the #include "stdafx.h" line.


            "though nothing  will keep us together  we can beat them  for ever and ever" rechi

            M Offline
            M Offline
            mpapeo
            wrote on last edited by
            #5

            well now it works even after re-including the header file. But now it does not create the notepad process and im amazed that its ID is -858993460 though it doesn't appear oam

            H 1 Reply Last reply
            0
            • M mpapeo

              well now it works even after re-including the header file. But now it does not create the notepad process and im amazed that its ID is -858993460 though it doesn't appear oam

              H Offline
              H Offline
              Hans Ruck
              wrote on last edited by
              #6

              It does. Check out the source again and look for GetStartupInfo(&si). Reinsert it into your code. No, wait! Just replace it with: ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) );


              "though nothing  will keep us together  we can beat them  for ever and ever" rechi

              M 1 Reply Last reply
              0
              • H Hans Ruck

                It does. Check out the source again and look for GetStartupInfo(&si). Reinsert it into your code. No, wait! Just replace it with: ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) );


                "though nothing  will keep us together  we can beat them  for ever and ever" rechi

                M Offline
                M Offline
                mpapeo
                wrote on last edited by
                #7

                I replaced the code lines you suggested but still it doesn't showup the process running, i.e. notepad or cmd. I tried to tackle it anyhow but still... and what i am concern with is that the process ID it shows is the same everytime i try to create it oam

                M 1 Reply Last reply
                0
                • M mpapeo

                  I replaced the code lines you suggested but still it doesn't showup the process running, i.e. notepad or cmd. I tried to tackle it anyhow but still... and what i am concern with is that the process ID it shows is the same everytime i try to create it oam

                  M Offline
                  M Offline
                  mpapeo
                  wrote on last edited by
                  #8

                  Ok i manage to solve it. Thanks anyway.:-O oam

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups