17,740
社区成员
发帖
与我相关
我的任务
分享
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
private void DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port) //handle process when there has data arrival
{
try
{
ClassMsg msg = new ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(Data))) as ClassMsg;
switch (msg.msgCommand)
{
case MsgCommand.Registered://register succeed
DialogResult = DialogResult.OK;
MessageBox.Show("does it come here?");
WritePrivateProfileString("yhzl", "ID", serID, PubClass.Get_Windows() + "\\Server.ini");
WritePrivateProfileString("yhzl", "Port", text_IP.Text.Trim(), PubClass.Get_Windows() + "\\Server.ini");
WritePrivateProfileString("yhzl", "Name", text_Name.Text.Trim(), PubClass.Get_Windows() + "\\Server.ini");
break;
}
} catch { }
}
private void F_Login_Load(object sender, EventArgs e)
{
//if there has not server.ini file while starting program
if (System.IO.File.Exists(PubClass.Get_Windows() + "\\Server.ini") == false)
{
F_SerSetup FrmSerSetup = new F_SerSetup(); //create and refer the register form
FrmSerSetup.Text = "User Register"; //set the name of the register form
if (FrmSerSetup.ShowDialog(this) == DialogResult.OK) //cruuent register form return OK..
{
FrmSerSetup.Dispose(); //delete all of the resource of current form
}
else
{
FrmSerSetup.Dispose();
DialogResult = DialogResult.Cancel;
}
}
//if there has server.ini file in windows directory
if (System.IO.File.Exists(PubClass.Get_Windows() + "\\Server.ini") == true)
{
Publec_Class.ServerIP = "";
Publec_Class.ServerPort = "";
//read server.ini file
StringBuilder temp = new StringBuilder(255);
//read server's ip address
GetPrivateProfileString("yhzl", "ID", "Server address read error.", temp, 255, System.Environment.CurrentDirectory + "\\Server.ini");
Publec_Class.ServerIP = temp.ToString();
//read port number
GetPrivateProfileString("yhzl", "Port", "Server address read error.", temp, 255, System.Environment.CurrentDirectory + "\\Server.ini");
Publec_Class.ServerPort = temp.ToString();
//read user name
GetPrivateProfileString("yhzl", "Name", "Server address read error.", temp, 255, System.Environment.CurrentDirectory + "\\Server.ini");
Publec_Class.ClientName = temp.ToString();
}
else
{
DialogResult = DialogResult.Cancel;
}
udpSocket1.Active = true; //start the custom udpsocket control...
}
//代码在F_SerSetup.cs中
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
private void DataArrival(byte[] Data, System.Net.IPAddress Ip, int Port) //handle process when there has data arrival
{
try
{
ClassMsg msg = new ClassSerializers().DeSerializeBinary((new System.IO.MemoryStream(Data))) as ClassMsg;
switch (msg.msgCommand)
{
case MsgCommand.Registered://register succeed
DialogResult = DialogResult.OK;
WritePrivateProfileString("MyQQ", "ID", serID, PubClass.Get_Windows() + "\\Server.ini");
WritePrivateProfileString("MyQQ", "Port", text_IP.Text.Trim(), PubClass.Get_Windows() + "\\Server.ini");
WritePrivateProfileString("MyQQ", "Name", text_Name.Text.Trim(), PubClass.Get_Windows() + "\\Server.ini");
MessageBox.Show("?");
break;
}
} catch { }
}