📄 firstmsg.cpp
字号:
#include "StdAfx.h"
#include "FirstMsg.h"
#include <stdio.h>
#include <string.h>
FirstMsg::FirstMsg(char* src,char* dest)
:MsgHeader(src,dest)
,m_nFirstData(0)
,m_nSecondData(0)
{
}
FirstMsg::FirstMsg(char* src,char* dest,int first,int second)
:MsgHeader(src,dest)
,m_nFirstData(first)
,m_nSecondData(second)
{
}
FirstMsg::~FirstMsg(void)
{
}
void FirstMsg::SetMsgData(int first,int second)
{
m_nFirstData=first;
m_nSecondData=second;
}
char* FirstMsg::toString(char** p)
{
char* str=NULL;
MsgHeader::toString(&str);
if(NULL !=str)
{
*p=new char[strlen(str)+1+20];
sprintf(*p,"%s%d%d",str,m_nFirstData,m_nSecondData);
delete[] str;
}else
{
}
return *p;
}
bool FirstMsg::savetofile(const char *path)
{
try
{
char str[512]={0};
sprintf(str,"%d",m_nMsgID);
WritePrivateProfileString("Header","messageID",str,path);
WritePrivateProfileString("Header","SourseAddress",m_strSrcAddr,path);
WritePrivateProfileString("Header","DestinationAddress",m_strDestAddr,path);
memset(str,0,512);
sprintf(str,"%d",m_nFirstData);
WritePrivateProfileString("Data","firstdata",str,path);
memset(str,0,512);
sprintf(str,"%d",m_nSecondData);
WritePrivateProfileString("Data","seconddata",str,path);
return true;
}catch(...)
{
return false;
}
}
MsgHeader* FirstMsg::loadfromfile(const char *path)
{
char srs[512]={0};
GetPrivateProfileString("Header","SourseAddress","",srs,512,path);
char des[512]={0};
GetPrivateProfileString("Header","DestinationAddress","",des,512,path);
char pstr[512]={0};
char qstr[512]={0};
GetPrivateProfileString("Data","thirddata","",pstr,512,path);
GetPrivateProfileString("Data","data1","",qstr,512,path);
//if (strlen(pstr)!=0)//找到了thirddata字段,表示是secondmessage类型
//{
// char first_data[512]={0};
// GetPrivateProfileString("Data","firstdata","",first_data,512,path);
// char second_data[512]={0};
// GetPrivateProfileString("Data","seconddata","",second_data,512,path);
// MsgHeader *msg=new SecondMsg(srs,des,first_data,atol(second_data),atol(pstr));
// return msg;
//}
//memset(pstr,0,512);
//GetPrivateProfileString("Data","data1","",pstr,512,path);
//if (strlen(pstr)==0)//找到了data1字段,表示是thirdmessge类型
//{
// char s_data[16]="data";
//}
//memset(pstr,0,512);
if (strlen(pstr)==0&&strlen(qstr)==0)
{
char f_data[512]={0};
GetPrivateProfileString("Data","firstdata","",f_data,512,path);
char s_data[512]={0};
GetPrivateProfileString("Data","seconddata","",s_data,512,path);
MsgHeader *msg=new FirstMsg(srs,des,atoi(f_data),atoi(s_data));
return msg;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -