标题:如何解决WinExec函数不能处理超长字符串命令的问题
取消只看楼主
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
结帖率:79.17%
已结贴  问题点数:15 回复次数:1 
如何解决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函数可以突破这个限制呢 ?
搜索更多相关主题的帖子: WinExec 函数 字符 命令 
2010-09-28 02:21
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
得分:0 
回复 2楼 红色警戒
恩,后来发现是notepad这个命令的问题,用ls就没有问题了

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2010-09-28 23:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-321551-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.128257 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved