| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 597 人关注过本帖
标题:[求助]不知道哪里错 CPOP3Client *pPOP3Client;
只看楼主 加入收藏
yihuanshou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-2
收藏
 问题点数:0 回复次数:6 
[求助]不知道哪里错 CPOP3Client *pPOP3Client;

在书上看到了一个新邮件检查器的例子,按着打了出来可是一直出现一个缺少存储类或类型说明符的错误!网上找了相关文章代码也和我的一模一样,实在是无法发现程序错在哪里,不知道哪位大虾能指点一下小弟,不胜感激!
下面给出所有源代码。只要先建一个C++的控制台应用程序(.net),直接把代码全部放进源文件就可以了。
不知道哪里错,急,希望各位高手帮忙发现问题!谢谢了!

搜索更多相关主题的帖子: 不胜感激 应用程序 源代码 控制台 源文件 
2006-05-02 04:45
yihuanshou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-2
收藏
得分:0 

#include "stdafx.h"

#using <mscorlib.dll>

#using <System.dll>

#using <System.Drawing.dll>

#using <System.Windows.Forms.dll>

using namespace System;

using namespace System::Drawing;

using namespace System::Windows::Forms;

using namespace System::Net::Sockets;

using namespace System::IO;

using namespace System::Data;

using namespace System::Text;

using namespace System::Collections;

using namespace System::ComponentModel;

public __gc class MainForm : public Form

{

private:

Label *label1; //三个标签

Label *label2;

Label *label3;

TextBox *ServerAdd; //输入框,表示服务器地址

TextBox *Username; //输入框,表示用户名

TextBox *Password; //输入框,表示用户密码

Button *btnChecker; //按钮

CPOP3Client *pPOP3Client;

void btn_Click( Object *sender, System::EventArgs *e );

int MailChecker();

public:

MainForm();

};

MainForm::MainForm()

{

StartPosition = FormStartPosition::CenterScreen; //开始运行时显示于屏幕中央

Text = "新邮件检查器";

Size = Drawing::Size( 300, 200 );

MaximizeBox = false; //让最大化按钮失效

FormBorderStyle = System::Windows::Forms::FormBorderStyle::Fixed3D;

label1 = new Label();

label1->Location = Drawing::Point( 20, 16 );

label1->Name = "label1";

label1->Size = Drawing::Size( 104, 23 );

label1->Text = "邮件服务器地址:";

label1->TextAlign = Drawing::ContentAlignment::MiddleLeft;

Controls->Add( label1 );

label2 = new Label();

label2->Location = Drawing::Point( 20, 56 );

label2->Name = "label2";

label2->Size = Drawing::Size( 104, 23 );

label2->Text = "用户名:";

label2->TextAlign = Drawing::ContentAlignment::MiddleLeft;

Controls->Add( label2 );

label3 = new Label();

label3->Location = Drawing::Point( 20, 96 );

label3->Name = "label3";

label3->Size = Drawing::Size( 104, 23 );

label3->Text = "密码:";

label3->TextAlign = Drawing::ContentAlignment::MiddleLeft;

Controls->Add( label3 );

ServerAdd = new TextBox();

ServerAdd->Location = Drawing::Point( 130, 16 );

ServerAdd->Name = "ServerAdd";

ServerAdd->Size = Drawing::Size( 136, 21 );

ServerAdd->TabIndex = 0;

ServerAdd->Text = "";

Controls->Add( ServerAdd );

Username = new TextBox();

Username->Location = Drawing::Point( 130, 55 );

Username->Name = "Username";

Username->Size = Drawing::Size( 136, 21 );

Username->TabIndex = 1;

Username->Text = "";

Controls->Add( Username );

Password = new TextBox();

Password->Location = Drawing::Point( 130, 94 );

Password->Name = "Password";

Password->PasswordChar = '*';

Password->Size = Drawing::Size( 136, 21 );

Password->TabIndex = 2;

Password->Text = "";

Controls->Add( Password );

btnChecker = new Button();

btnChecker->Location = Drawing::Point( 177, 130 );

btnChecker->Name = "btnChecker";

btnChecker->Size = Drawing::Size( 90, 25 );

btnChecker->TabIndex = 3;

btnChecker->Text = "开始检查邮箱";

btnChecker->add_Click( new EventHandler( this, &MainForm::btn_Click) );

Controls->Add( btnChecker );

}

2006-05-02 04:46
yihuanshou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-2
收藏
得分:0 

public __gc class CPOP3Client

{

public:

//默认的构造函数

CPOP3Client():

m_Client(NULL),

m_strPOP3HostName(String::Empty),

m_strUserName(String::Empty),

m_strPassword(String::Empty),

m_strStatus(new String("OK"))

{}

//方法get_POP3HostName:获得POP3服务器地址

__property String *get_POP3HostName()

{

return m_strPOP3HostName;

}

//方法set_POP3HostName:设置POP3服务器地址

__property void set_POP3HostName(String *strPOP3HostName)

{

m_strPOP3HostName = strPOP3HostName;

}

//方法get_UserName:获得用户名

__property String *get_UserName()

{

return m_strUserName;

}

//方法 set_UserName:设置用户名

__property void set_UserName(String *strUserName)

{

m_strUserName = strUserName;

}

//方法get_Password:获得密码

__property String *get_Password()

{

return m_strPassword;

}

//方法 set_Password:设置密码

__property void set_Password(String *strPassword)

{

m_strPassword = strPassword;

}

//方法get_Status:获取状态

__property String *get_Status()

{

return m_strStatus;

}

__property int get_NumberOfMessages()

{

String *strResponse = String::Empty;

String *strNrOfMessages; //邮件数目

Char separator __gc[] = new Char __gc[1]; //托管数组

separator[0] = ' ';

try

{

if(!ConnectToServer()) //连不上服务器

return -1;

if(!SendCommand(String::Concat(S"USER ", m_strUserName),&strResponse))

{

return -1;

}

if(!SendCommand(String::Concat(S"PASS ", m_strPassword),&strResponse))

{

return -1;

}

if(!SendCommand(S"STAT ", &strResponse))

{

return -1;

}

//从回复信息中获得新邮件的数目

strNrOfMessages = strResponse->Split(separator)[1];

return Convert::ToInt32(strNrOfMessages);

}

catch(Exception *e)

{

m_strStatus = String::Concat(S"Error:",e->Message);

return -1;

}

__finally

{

DisconnectFromServer();

}

}

private:

TcpClient *m_Client; //TcpClient对象

String *m_strPOP3HostName; //字符串表示服务器地址

String *m_strUserName; //字符串表示用户名字

String *m_strPassword; //字符串表示密码

String *m_strStatus; //状态

void Close()

{

if (m_Client != NULL)

{

m_Client->Close();

m_Client = NULL;

}

}

2006-05-02 04:47
yihuanshou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-2
收藏
得分:0 

protected:

bool ConnectToServer()

{

String *strReadBuffer; //缓冲器

StreamReader *streamRead; //读字符流的StreamReader对象

//关闭已存在的连接

Close();

//和服务器建立一个连接

m_Client = new TcpClient(m_strPOP3HostName, 110);

//创建一个读取流

streamRead = new StreamReader(m_Client->GetStream(), Encoding::ASCII );

//保存到缓冲器中

strReadBuffer = streamRead->ReadLine();

//忽略buffer中的多余部分

streamRead->DiscardBufferedData();

//回复是否以+OK开头,是则成功,否则失败

if(strReadBuffer->StartsWith("+OK"))

return true;

else

{

Close();

return false;

}

}

bool SendCommand(String *strCommand, String *pstrOutput)

{

Byte outbuffer __gc[]; //声明Byte类型的托管数组

StreamReader *streamRead;

NetworkStream *streamWrite;

String *strRequest;

if (m_Client == NULL)

return false;

//给每个命令添加结束符

strRequest = String::Concat(strCommand, S"\r\n");

//创建一个从套接字读取数据的流

streamWrite = m_Client->GetStream();

streamRead = new StreamReader(streamWrite, Encoding::ASCII);

//将字符串转化为字节流将它写入套接字中

outbuffer = Encoding::ASCII->GetBytes(strRequest);

streamWrite->Write(outbuffer,0,outbuffer->Length);

//从套接字读取回复

*pstrOutput = streamRead->ReadLine();

//忽略buffer中的多余部分

streamRead->DiscardBufferedData();

return( *pstrOutput)->StartsWith(S"+OK") ? true : false;

}

void DisconnectFromServer()

{

String *strResponse = String::Empty;

SendCommand("QUIT", &strResponse);

Close();

}

};

void MainForm::btn_Click( Object *sender, System::EventArgs *e )

{

if( sender->Equals( this ->btnChecker ) )

{

if( ServerAdd->Text != " "

&& this ->Username->Text != " "

&& this ->Password->Text != " " )

{

int number = this ->MailChecker();

if( number > 0 )

{

String *info = new String( "你有" );

info->Concat(number.ToString());

info->Concat(S"封新邮件!");

MessageBox::Show( info->ToString(),"InfoBox",

MessageBoxButtons::OK,MessageBoxIcon::Information );

}

else if( number == 0 )

{

MessageBox::Show( "你暂时还没有新邮件。","InfoBox",

MessageBoxButtons::OK,MessageBoxIcon::Information );

}

}

}

}

int MainForm::MailChecker()

{

int numberOfMails;

//创建一个POP3Client对象

pPOP3Client = new CPOP3Client();

//设置各项属性

pPOP3Client->POP3HostName = this->ServerAdd->Text->ToString();

pPOP3Client->UserName = this->UserName->Text->ToString();

pPOP3Client->Password = this->Password->Text->ToString();

//获得新邮件数目

numberOfMails = pPOP3Client->NumberOfMessages;

if( numberOfMails < 0)

MessageBox::Show( "发生错误!!!请检查设置。","InfoBox",

MessageBoxButtons::OK,MessageBoxIcon::Error );

return numberOfMails;

}

int _stdcall WinMain()

{

// TODO: 请用您自己的代码替换下面的示例代码。

Application::Run(new MainForm());

return 0;

}

2006-05-02 04:47
yihuanshou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-2
收藏
得分:0 

谁能帮我看看呀。谢谢

2006-05-03 02:38
yihuanshou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-2
收藏
得分:0 

有人能解决吗?

2006-05-04 21:32
yihuanshou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-5-2
收藏
得分:0 

在开头添加类成员的时候一直出现缺少存储类或类型说明符的错误

错误是
1:"MainForm::CPOP3Client"缺少存储类或类型说明符
2:"MainForm::pPOP3Client"缺少存储类或类型说明符

错误指针指向MianForm类的私有成员函数中

2006-05-05 00:12
快速回复:[求助]不知道哪里错 CPOP3Client *pPOP3Client;
数据加载中...
 
   



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

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