环境vc60 + win2000 + 补丁
1、建立工程Test
2、在TestApp中增加成员函数 void Connect()
3、在Connect() 中增加代码:
CInternetSession session ;
CFtpConnection * pFtpConnection ; try
{
pFtpConnection = session.GetFtpConnection (....) ;
}
catch(...)
{ .... } 这段代码运行正常,然后我现在想把 session 和 pFtpConnection 这两个变量在TestApp中进行声明,也就是做为TestApp的public成员。去掉Connect()中的变量去掉。变成如下形式。
// CInternetSession session ;
// CFtpConnection * pFtpConnection ; try
{
pFtpConnection = session.GetFtpConnection (....) ;
}
catch(...)
{ .... }程序就不能运行了,一启动程序就报错。我应该怎样改,才能使程序能正常运行?做为正在学习的新手,实再是没有多少分可送,请老手们指点一下,谢谢。
1、建立工程Test
2、在TestApp中增加成员函数 void Connect()
3、在Connect() 中增加代码:
CInternetSession session ;
CFtpConnection * pFtpConnection ; try
{
pFtpConnection = session.GetFtpConnection (....) ;
}
catch(...)
{ .... } 这段代码运行正常,然后我现在想把 session 和 pFtpConnection 这两个变量在TestApp中进行声明,也就是做为TestApp的public成员。去掉Connect()中的变量去掉。变成如下形式。
// CInternetSession session ;
// CFtpConnection * pFtpConnection ; try
{
pFtpConnection = session.GetFtpConnection (....) ;
}
catch(...)
{ .... }程序就不能运行了,一启动程序就报错。我应该怎样改,才能使程序能正常运行?做为正在学习的新手,实再是没有多少分可送,请老手们指点一下,谢谢。
解决方案 »
- 在MFC 下ClassView Globals 下的函数是如何添加的呢?
- 两个星星,散点分吧
- 菜问题:如何定义一个整个工程都有效的宏?
- 如何播放mp3等形式的音乐,循环播放?
- 如何实现TAB CONTROL的界面显示
- 如何拦截系统的下载消息!
- 0x5f4359eb指令在引用的“0x000000000”的内存不能为read
- 我没有可用分了!
- 菜鸟问题2:我的Dialog上已经添加了若干个控件,可为什么当建立类向导时在Object IDs下看不到他们的ID?
- 这分数这么容易拿,你不动心吗?
- 关于CRichEditCtrl的ITextDocument接口open与save问题
- 如何测度引用的对象是否为空引用?
// Default parameters mean the access method in the registry
// (that is, set by the "Internet" icon in the Control Panel)
// will be used.public:
CInternetSession sess(_T("My FTP Session"));
CFtpConnection* pConnect = NULL;......try
{
// Request a connection to ftp.microsoft.com. Default
// parameters mean that we'll try with username = ANONYMOUS
// and password set to the machine name @ domain name
pConnect = sess.GetFtpConnection(_T("ftp.microsoft.com")); // use a file find object to enumerate files
CFtpFileFind finder(pConnect); // start looping
BOOL bWorking = finder.FindFile(_T("*")); while (bWorking)
{
bWorking = finder.FindNextFile();
_tprintf_s(_T("%s\n"), (LPCTSTR)finder.GetFileURL());
}
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
_tprintf_s(_T("ERROR! %s\n"), sz);
pEx->Delete();
}
#include <afxinet.h>
#include <stdio.h>class MySesion : public CWinApp
{
public:
CInternetSession sess;
CFtpConnection* pConnect;public:
BOOL Connect();
};BOOL MySesion::Connect()
{
try
{
pConnect = sess.GetFtpConnection(_T("ftp.microsoft.com"));
CFtpFileFind finder(pConnect);
BOOL bWorking = finder.FindFile(_T("*")); while (bWorking)
{
bWorking = finder.FindNextFile();
printf(_T("%s\n"), (LPCTSTR)finder.GetFileURL());
}
return TRUE;
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz, 1024);
printf(_T("ERROR! %s\n"), sz);
pEx->Delete();
}
return FALSE;
}void main()
{
MySesion ms;
if(ms.Connect())
printf("操作成功!\r\n");
else
printf("操作失败!\r\n");
}
cl Connect.cpp /MT运行结果:
try
{
pFtpConnection = session.GetFtpConnection("192.168.0.26","test_user","abc123",NULL,FALSE) ;
}在我把
CInternetSession session ;
CFtpConnection * pFtpConnection ;
放到TestApp()里就不行了。另外我建立的不是控制台的工程,是对话框工程。
你的App类构造函数
CXXApp::CXXApp() : session(_T("My Session"))
{
....
}