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 7782827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:39:44+00:00 2026-06-01T19:39:44+00:00

I was reading about CreateProcess function in c++ and I wanted to try it.

  • 0

I was reading about CreateProcess function in c++ and I wanted to try it. Basic idea of the code is to have my main execute another process (notepad). Really, it’s just the basic code. When I run the program, I get:

First-chance exception at 0x752bb763 in createprocess.exe: 0xC0000005: Access violation writing location 0x00be57b8.
Unhandled exception at 0x752bb763 in createprocess.exe: 0xC0000005: Access violation writing location 0x00be57b8.

When I make a break point for where the error occurs, I get taken to tidtable.c (which is for accessing threads, I guess).
Specifically in tidtable.c at CRTIMP PFLS_GETVALUE_FUNCTION __cdecl __set_flsgetvalue()
I really don’t know what or how to avoid this problem. The error occurs with the CreateProcess call (ie, it never outputs the “out of create”).

My code is:

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <strsafe.h>
#include <direct.h>
#include <string.h>
#include <conio.h>

int main(VOID)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

        //allocate memory
    ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));


fprintf(stderr, "This is just a test");

//create child process
if (!CreateProcess(NULL,
    L"C:\\Windows\\Notepad.exe",
    NULL,
    NULL,
    FALSE,
    0,
    NULL,
    NULL,
    &si,
    &pi))
{
        fprintf(stderr, "create process failed");

        return -1;
}
fprintf(stderr, "out of create");

    //parent waits for child to complete
WaitForSingleObject(pi.hProcess, INFINITE);

fprintf(stderr, "after wait");

printf("Child Complete");

    //close handle
CloseHandle(pi.hProcess);
//  CloseHandle(pi.hthread);

}

If anyone knows how to overcome this problem, your help would be appreciated.

  • 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-06-01T19:39:45+00:00Added an answer on June 1, 2026 at 7:39 pm

    The problem is that the second parameter of the CreateProcess function is an in/out parameter.

    If you specify it as a string like you did, it is a constant string and the function when it is called cannot write to the memory location, thus you have a memory access violation. The correct way is to call your function like this:

    LPTSTR szCmdline = _tcsdup(TEXT("C:\\Windows\\Notepad.exe"));
    
    //create child process
    if (!CreateProcess(NULL,
        szCmdline,
        NULL,
        NULL,
        FALSE,
        0,
        NULL,
        NULL,
        &si,
        &pi))
    {
        fprintf(stderr, "create process failed");
    
        return -1;
    }
    

    You may also want to read this blog article.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading about both Linq to SQL and Entity Framework I have developed the impression
In reading about C#, I have come across the terms data transfer type and
After reading about both, I just have curiosity, how programming community uses this? In
After reading about Enitity Framework , i have some questions: 1] What is the
When reading about SQL Injection and XSS i was wondering if you guys have
After reading about it for so long, I now have chance to get my
I have been reading about how read.table is not efficient for large data files.
I've been reading about reliable messaging and have a few questions that I haven't
In reading about SCM (software configuration mgt, not supply chain mgt), I have seen
After reading about VA_NARG I tried to implement function overloading depending on number of

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.