Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
UpdateData(TRUE);

SHELLEXECUTEINFOA sei;
memset(&sei, 0, sizeof SHELLEXECUTEINFOA);
sei.cbSize = sizeof SHELLEXECUTEINFOA;
sei.fMask = SEE_MASK_NOCLOSEPROCESS /*| SEE_MASK_FLAG_NO_UI*/;
sei.lpVerb = "runas";
sei.lpDirectory = GetModulePath();
sei.lpFile = "curl.exe";
sei.lpParameters = m_strCmd;
//MessageBox(m_strCmd, _T("tip"), MB_OK);
sei.nShow = SW_SHOW;
if (!ShellExecuteExA(&sei))
{
    CString strLog;
    strLog.Format(_T("启动curl失败(code:0x%x)"), GetLastError());
    MessageBox(strLog);
    return;
}

In this code,lpParameters is a long string which length over 2048,errors occured when codes run to the"ShellExecuteExA(&sei)",the error is "Unhandled exception in RunCurl.exe(KERNELE32.DLL):0xC0000005:Access Violation."(RunCurl.exe is my project's name).It seems a memory access,but i dont know what makes this.If I reduce the lenth of lpParameters then this function works normal.If I run this function with a long lpParameters(length over 2048) in CMD then it works normal too.And this error never occured on WIN7,I guess if the SHELLEXECUTEINFOA cannot receive a too long string on XP?

What I have tried:

read msdn,debug in xp and WIN7,google
Posted
Updated 28-Aug-16 21:17pm

1 solution

You are right. On the "good old" Windows XP the parameter cant be so long.

Now you know why Windows 7 is more modern ;-)
 
Share this answer
 
Comments
TimGallin 29-Aug-16 4:34am    
Yup,thanks,now i know the reason.If I use ShellExecute on XP,the lpParameters's limitation is around 2048,the CreateProcess's limitation is around 32767,the CMD.EXE is around 8192.Is there a solution to resolve this problem when I use ShellExecute ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900