VS2005 托管调试问题

safinlove 2009-03-19 05:22:56
#pragma once

namespace Tcp {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Threading;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::IO;

/// <summary>
/// Form1 摘要
///
/// 警告: 如果更改此类的名称,则需要更改
/// 与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
/// “资源文件名”属性。否则,
/// 设计器将不能与此窗体的关联
/// 本地化资源正确交互。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此处添加构造函数代码
//
readThread= gcnew Thread( gcnew ThreadStart(this,RunServer));
readThread->Start();
}

protected:
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ inputTextBox;
protected:
private: System::Windows::Forms::TextBox^ displayTextBox;

private:Socket ^connection;
private:Thread ^readThread;

private:NetworkStream ^socketStream;
private:BinaryWriter ^writer;
private:BinaryReader ^reader;

private:
/// <summary>
/// 必需的设计器变量。
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
void InitializeComponent(void)
{
this->inputTextBox = (gcnew System::Windows::Forms::TextBox());
this->displayTextBox = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// inputTextBox
//
this->inputTextBox->Location = System::Drawing::Point(12, 17);
this->inputTextBox->Name = L"inputTextBox";
this->inputTextBox->Size = System::Drawing::Size(357, 21);
this->inputTextBox->TabIndex = 0;
this->inputTextBox->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::inputTextBox_KeyDown);
//
// displayTextBox
//
this->displayTextBox->Location = System::Drawing::Point(12, 52);
this->displayTextBox->Multiline = true;
this->displayTextBox->Name = L"displayTextBox";
this->displayTextBox->ReadOnly = true;
this->displayTextBox->Size = System::Drawing::Size(357, 202);
this->displayTextBox->TabIndex = 1;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(379, 266);
this->Controls->Add(this->displayTextBox);
this->Controls->Add(this->inputTextBox);
this->Name = L"Form1";
this->Text = L"server";
this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
private: System::Void inputTextBox_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
try{
if (e->KeyCode == Keys::Enter&&connection != NULL)
{
writer->Write(String::Concat(L"SERVER>>>",inputTextBox->Text));
displayTextBox->Text= String::Concat(displayTextBox->Text,L"\r\nServer>>> ",inputTextBox->Text);

if(inputTextBox->Text->Equals(L"TERMINATE"))
connection->Close();

inputTextBox->Clear();
}
}
catch(SocketException ^)
{
displayTextBox->Text= String::Concat(displayTextBox,L"\nError writing object" );
}
}

private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e)
{
System::Environment::Exit(System::Environment::ExitCode);
}

public: void RunServer()
{
TcpListener ^listener;
int counter =1;

try
{
listener= gcnew TcpListener( gcnew IPAddress( static_cast<_int64>(0)),4500);
listener->Start();

while( true)
{
displayTextBox->Text=L"Waiting for connection\r\n";
socketStream= gcnew NetworkStream( connection);
writer= gcnew BinaryWriter( socketStream);
reader= gcnew BinaryReader( socketStream);
displayTextBox->Text= String::Concat(displayTextBox->Text,L"Connection ",counter.ToString(),L" received.\r\n");
writer->Write(L"SERVER>>> Connection successful");
inputTextBox->ReadOnly= false;
String ^theReply= L"";
do
{
try
{
theReply= reader->ReadString();
displayTextBox->Text= String::Concat(displayTextBox->Text,L"\r\n",theReply);
}
catch( Exception ^)
{
break;
}
}
while( !theReply->Equals( L"CLIENT>>> TERMINATE")&& connection->Connected);
displayTextBox->Text= String::Concat(displayTextBox->Text,L"\r\nUser terminated connection");
inputTextBox->ReadOnly=true;
writer->Close();
reader->Close();
socketStream->Close();
connection->Close();
++counter;
}
}
catch( Exception ^error)
{
MessageBox::Show( error->ToString());
Application::Exit();
}
}
};
}

错误 1 error C3867: 'Tcp::Form1::RunServer': function call missing argument list; use '&Tcp::Form1::RunServer' to create a pointer to member g:\projects\tcp\tcp\Form1.h 34
错误 2 error C3350: 'System::Threading::ThreadStart' : a delegate constructor expects 2 argument(s) g:\projects\tcp\tcp\Form1.h 34
错误 3 error C2065: 'NULL' : undeclared identifier g:\projects\tcp\tcp\Form1.h 112
...全文
165 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangsh3002 2009-07-22
  • 打赏
  • 举报
回复
readThread= gcnew Thread( gcnew ThreadStart(this,&RunServer));

if (e->KeyCode == Keys::Enter&&connection != nullptr)
马少华 2009-07-21
  • 打赏
  • 举报
回复
纯托管代码,直接用c#好了。
liubuweiright 2009-04-08
  • 打赏
  • 举报
回复
up

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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