大家帮我看看有什么问题吧

skywatcher 2004-04-01 06:24:39
就这么一点代码,不知怎么回事,只要用上,程序就喜欢自动退出,或者因为出现叫做什么 内存访问无效(英文,我自己瞎翻的)什么的错误而退出!
我实在没有看出错在哪儿,谁给点意见?


int ClassName::Send(LPSTR QQNumber, LPSTR msgin,LPSTR msgout)
{
CString m_download,cmsgin(msgin);
char * m_location;
CInternetSession mySession;
CInternetFile * myFile=NULL;
m_location="http://localhost/?";
strcat(m_location,msgin);
try
{
myFile=(CInternetFile*)mySession.OpenURL(m_location,1,INTERNET_FLAG_RELOAD,0);
}
catch(CInternetException * pEx)
{
myFile=NULL;
pEx->Delete();
return 0;
}
if(myFile)
{
CString line;
for(int i=0;i<10 && myFile->ReadString(line);i++)
m_download+=line+"\r\n";
myFile->Close();
delete myFile;
}
if(m_download=="")
{
m_download+="Error!";
}
wsprintf(msgout,"%s",m_download);
msgin="";
return 1;
}
...全文
63 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
rorot 2004-04-01
  • 打赏
  • 举报
回复
int ClassName::Send(LPSTR QQNumber, LPSTR msgin,LPSTR msgout)
{
// 这里用字符数组(栈)
char m_location[1024];

CString m_download,cmsgin(msgin);
CInternetSession mySession;
CInternetFile * myFile=NULL;

// 字符串复制
strcpy( m_location, "http://localhost/?" );

strcat(m_location,msgin);
try
{
myFile=(CInternetFile*)mySession.OpenURL(m_location,1,INTERNET_FLAG_RELOAD,0);
}
catch(CInternetException * pEx)
{
myFile=NULL;
pEx->Delete();
return 0;
}
if(myFile)
{
CString line;
for(int i=0;i<10 && myFile->ReadString(line);i++)
m_download+=line+"\r\n";
myFile->Close();
delete myFile;
}
if(m_download=="")
{
m_download+="Error!";
}
wsprintf(msgout,"%s",m_download);
msgin="";
return 1;
}
abitz 2004-04-01
  • 打赏
  • 举报
回复
>> 应该怎样分配才算好呢?有一段源代码吗?
>> 还有,我总觉得不应该是设个问题一样!
>> 因为如果是这个问题,就应该整个不能通过编译阿

这个是runtime error,编译不会有问题。
给m_location分配空间 或 声明为c-style string 或 string都能解决这个问题。
zhjie007 2004-04-01
  • 打赏
  • 举报
回复
把m_location定义成CString的,试试
cgsw12345 2004-04-01
  • 打赏
  • 举报
回复
应该是 abitz(阿奈) 兄弟所说的问题 试试使用new 和delete
分配内存看能不能通过!
skywatcher 2004-04-01
  • 打赏
  • 举报
回复
应该怎样分配才算好呢?有一段源代码吗?
还有,我总觉得不应该是设个问题一样!
因为如果是这个问题,就应该整个不能通过编译阿
abitz 2004-04-01
  • 打赏
  • 举报
回复
m_location="http://localhost/?";
strcat(m_location,msgin);
这个不行。m_location="http://localhost/?"使m_location指向一块只读空间,
不能再进行连接。
应该先分配空间,再strcpy。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧