如何解决WinExec函数不能处理超长字符串命令的问题
程序代码:
#include <windows.h> #include <iostream.h> #include "string" using namespace std; std::string longcmd = "notepad "; std::string longfilename = "zhongyundezhongyundezhongyundezhongyundezhongyundezhongyunde"; void initcmd() { int i = 0; for (i=0;i<1000;i++) { longcmd += longfilename; } longcmd += ".txt"; } void main(int argc,char *argv[]) { cout <<"Opening with WinExec\n"; initcmd(); if (WinExec(longcmd.c_str(),SW_SHOW) <32) MessageBox(NULL,"Can't WinExec",NULL,MB_OK); }以上程序的initcmd()中,如果修改for (i=0;i<1000;i++)为for (i=0;i<1;i++)能正常执行,但是现在由于longcmd.c_str()命令所对应的字符串超出了WinExec函数的允许范围,导致WinExec(longcmd.c_str(),SW_SHOW)执行出错,有什么办法能解决这个问题吗?或者用别的API函数可以突破这个限制呢 ?