Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 712295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:49:57+00:00 2026-05-14T04:49:57+00:00

hello i want to get startet with programming with WIN32, therefore i wrote a

  • 0

hello i want to get startet with programming with WIN32, therefore i wrote a programm that creates a process but in the line of code where i create the process the programm gets an error an dosn’t work (abend). i don’t know if the code in programm 1 is wrong or the code in the second programm that should be created by the first. ( I don’t know if the code in the first programm after “createprocess” is right because i didn’t get further with debugging, because in this line i get the error.(i tested it without the cout,waitforobject and close handle but i didn’t work either )).

First Programm:

#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

void main()
{

bool ret;
bool retwait;

STARTUPINFO startupinfo;
GetStartupInfo (&startupinfo);

PROCESS_INFORMATION pro2info;

    ret = CreateProcess(NULL, L"D:\\betriebssystemePRA1PRO2.exe", NULL, NULL, false, CREATE_NEW_CONSOLE, NULL,
        NULL, &startupinfo, &pro2info);


    cout<<"hProcess: "<<pro2info.hProcess<<endl;
    cout<<"dwProcessId: "<<pro2info.dwProcessId <<endl;

    retwait= WaitForSingleObject (pro2info.hProcess, 100);
    retwait= WaitForSingleObject (pro2info.hProcess, 100);

    CloseHandle (pro2info.hProcess);//prozesshandle schließen 

    retwait= WaitForSingleObject (pro2info.hProcess, 100);



ExitProcess(0);


} 

Seconde Programm:

#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

void main()
{


    int b;

    b=GetCurrentProcessId();

    cout<<b<<endl;
    cout<<"Druecken Sie Enter zum Beenden"<<endl;
    cin.get();
        //warten bis Benutzer bestätigt

    Sleep (700);
    ExitProcess(0);

    cout<<"test";
}

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:49:57+00:00Added an answer on May 14, 2026 at 4:49 am

    Notice the type of the lpCommandLine parameter to CreateProcess — it is LPTSTR, not LPCTSTR, i.e. it is not const.

    This means that CreateProcess reserves the right to actually modify the contents of lpCommandLine. However, you have provided a pointer to a string literal as parameter, and string literals are immutable (they come from your program’s read-only data segment and attempts to alter them will typically result in an access violation error.)

    To fix this, simply change your code not to use an immutable string literal:

    wchar_t wcsCommandLine[] = L"D:\\betriebssystemePRA1PRO2.exe";
    ret = CreateProcess(NULL, wcsCommandLine, NULL, NULL, ...
    

    Interestingly enough, CreateProcessW (UNICODE) attempts to write to lpCommandLine whereas CreateProcessA (ANSI) does not, and surprise — your first program is built as UNICODE (were you to build it as ANSI it would work out of the box, at least on Windows XP.)

    I can confirm that, with the above modification, your code works.

    Also note that:

    • unless you need to specify D:\\betriebssystemePRA1PRO2.exe‘s window title, position etc. you do not need to supply a STARTUPINFO structure at all, you can simply pass lpStartupInfo as NULL and a default will be used
    • you should not be calling WaitForSingleObject on a closed handle
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.