CreateProcess Access violation(越界访问)
https://stackoverflow.com/questions/11339186/createprocess-fails-with-an-access-violation
My aim is to execute an external executable in my program. First, I used system()
function, but I don't want the console to be seen to the user. So, I searched a bit, and found CreateProcess()
function. However, when I try to pass a parameter to it, I don't know why, it fails. I took this code from MSDN, and changed a bit:
- #include <windows.h>
- #include <stdio.h>
- #include <tchar.h>
- void _tmain( int argc, TCHAR *argv[] )
- {
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory( &si, sizeof(si) );
- si.cb = sizeof(si);
- ZeroMemory( &pi, sizeof(pi) );
- /*
- if( argc != 2 )
- {
- printf("Usage: %s [cmdline]\n", argv[0]);
- return;
- }
- */
- // Start the child process.
- if( !CreateProcess( NULL, // No module name (use command line)
- L"c:\\users\\e\\desktop\\mspaint.exe", // Command line
- NULL, // Process handle not inheritable
- NULL, // Thread handle not inheritable
- FALSE, // Set handle inheritance to FALSE
- , // No creation flags
- NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
- &si, // Pointer to STARTUPINFO structure
- &pi ) // Pointer to PROCESS_INFORMATION structure
- )
- {
- printf( "CreateProcess failed (%d).\n", GetLastError() );
- return;
- }
- // Wait until child process exits.
- WaitForSingleObject( pi.hProcess, INFINITE );
- // Close process and thread handles.
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
- }
However, this code crated access violation somehow. Can I execute mspaint without showing user the console?
Thank you very much.
- 2For one thing,
CreateProcess
requires that its second parameter (if provided) be a non-const string. I'm not sure that this is a problem in practice, but I wanted to mention it for completeness. – reuben Jul 5 '12 at 6:56 - ...and otherwise, where the is AV happening? Do you have a call stack? – reuben Jul 5 '12 at 6:57
- @reuben Uhm... I'm not quite sure, but I guess this is the output of call stack:
kernel32.dll!76da70ac() [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll] > msvcr100d.dll!_nh_malloc_dbg(unsigned int nSize, int nhFlag, int nBlockUse, const char * szFileName, int nLine) Line 302 + 0x1d bytes C++
– John Doe Jul 5 '12 at 7:03
Try this, it should work.
- TCHAR lpszClientPath[]= TEXT("c:\\users\\e\\desktop\\mspaint.exe");
- if(!CreateProcess(NULL, lpszClientPath, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS|CREATE_NEW_CONSOLE|CREATE_UNICODE_ENVIRONMENT,NULL, NULL, &si, &pi))
- {
- printf( "CreateProcess failed (%d).\n", GetLastError() );
- return;
- }
CreateProcess Access violation(越界访问)的更多相关文章
- VS2010程序崩溃,报错Unhandled exception at **.exe:0xC0000005: Access violation reading location 0x000000008899.
最近被派到另外一个组支援,从而从Linux下开发暂转到Windows下开发,个人觉得Windows自己搞的一套并不那么完美,坑多. 网文可能出现的原因: 未处理的异常: 0xC0000005: 读取位 ...
- 如何捕获access violation异常
文章目录 access violation的由来 access violation的实例 Win32 exception SEH异常与C++标准异常 捕获方法 1.access violation的由 ...
- Access Violation at address 00000000.Read of address 00000000 解决办法
是数组越标或没有初始化某个对象之类的问题,搂住细细检查一下代码, 使用指针前未做检查,而这个指针未初始化. 可能是new后没有delete,这样出现溢出的可能性比较大 检查代码或者跟踪试试 使 ...
- Navicat 提示 Access violation at address ***(如004ECCF4) in module ‘navicat.exe’. Read of address ***(如00000048)
Navicat 提示 Access violation at address ***(如004ECCF4) in module ‘navicat.exe’. Read of address ***(如 ...
- 解决 “access violation at address xxxxxxxxx”错误
在进行磁盘整理的时候,打开Foxmail的时候出现了“access violation at address32383137”错误 和“access violation at address00000 ...
- PHP has encountered an Access Violation at 01F4A622解决方法
php搭建的网站出现以下问题的解决方法分享: Z-blog,DedeCMS,Dsicuz!,PhpWind,PhpCMS,帝国CMS等都有可能出现php访问冲突问题. 今天访问网站发现出现了一个错误& ...
- cout显示Mat类对象报错Access Violation
AV(Access Violation)错误:非法访问. image_match.exe 中的 0x0000002a 处有未经处理的异常: 0xC0000005: Access violation 程 ...
- 使用scanf_s报错:0xC0000005: Access violation writing location 0x00000000
在vs2010中写了一行scanf("%s",name); 调式时 提示warning , 提示修改为scanf()使用可能会存在不安全,建议使用scanf_s() 但是我修改成s ...
- Access Violation分成两大类:运行期和设计期(很全的解释)
用Delphi开发程序时,我们可以把遇到的Access Violation分成两大类:运行期和设计期. 一.设计期的Access Violation 1.硬件原因 在启动或关闭Delphi IDE以 ...
随机推荐
- javascript 布尔类型
true和false 表达式为false的情况 1 false 2 NaN 3 0 4 字符串的空 " " 5 null 6 undefined
- 关于 .dyib 文件
.dylib 意味着这是一个动态链接库. libz.dylib 是提供zip压缩.解压缩的库. 库的接口请 #import "zlib.h"
- UVaLive 6581 && Gym 100299B What does the fox say? (模拟+STL)
题意:给定一些动物的叫声,然后再定某些动物的叫声,让你去除这些叫声后得到的叫声. 析:先存储所有的叫声,然后用map来记录其他的叫声,在输出时再判定一下就好. 代码如下: #pragma commen ...
- Unity网格合并_材质合并[转]
http://blog.csdn.net/chenggong2dm/article/details/41699029
- Swift3.0 控制流
常用的一些判断方式 //for in let numberList = [, , , , ] //获取第一个元素 !拆包 print(numberList.first!)//1 //获取最后一个元素 ...
- 瞎比比系列---1st
A - 项目管理HDU4858 /* 题意: 这个项目有n个节点, 两个节点间可能有多条边,不过一条边的两端必然是不同的节点. 0的时候:接下来两个数u v表示给项目u的能量值加上v: 1的时候: 这 ...
- 前端代码规范(转载 http://codeguide.bootcss.com/)
http://codeguide.bootcss.com/ HTML 语法 HTML5 doctype 语言属性(Language attribute) 字符编码 IE 兼容模式 引入 CSS 和 J ...
- iOS 加载Viewcontroller的几种方法
// 一.根据StoryboardID(需要在Storyboard设置),通过ViewController所在的Storyboard来加载: UIStoryboard *storyboard = [U ...
- python3_linux安装
python安装包地址 https://www.python.org/ftp/python/ 如果没有c complie,就安装: yum -y install gcc gcc-c++ 在编译安装之前 ...
- KMP算法笔记(云笔记图片版)