mfc中怎么把cstring变量放进已经定义好的结构体的char数组中
结构体:typedefstruct{charSCA[16];charTPA[16];charTP_PID;charTP_DCS;charTP_SCTS[16];charT...
结构体:
typedef struct
{
char SCA[16];
char TPA[16];
char TP_PID;
char TP_DCS;
char TP_SCTS[16];
char TP_UD[161];
char index;
} SM_PARAM;
void CCommassistDlg::OnBtnHandsend()
{
// TODO: Add your control notification handler code here
CString m_strOut;
CString m_jsha;
UpdateData(TRUE);
GetDlgItemText(IDC_EDIT_TX,m_strOut);
UpdateData(TRUE);
GetDlgItemText(IDC_EDIT_JSHA,m_jsha);
//填充SM_PARAM结构体内容
SM_PARAM smParam;
smParam=CreateSM_PARAM(m_jsha,m_strOut);
我要利用CreateSM_PARAM函数把变量m_jsha,m_strOut分别放进char TPA[16]; char TP_UD[161]; 该怎么做?
SM_PARAM CreateSM_PARAM (CString m_jsha,CString m_strOut)
{
SM_PARAM *p;
p=NULL;
p = new SM_PARAM();
p->TPA = m_jsha;
p->TP_UD = m_strOut;
return *p;
}
我这样编写提示出错 展开
typedef struct
{
char SCA[16];
char TPA[16];
char TP_PID;
char TP_DCS;
char TP_SCTS[16];
char TP_UD[161];
char index;
} SM_PARAM;
void CCommassistDlg::OnBtnHandsend()
{
// TODO: Add your control notification handler code here
CString m_strOut;
CString m_jsha;
UpdateData(TRUE);
GetDlgItemText(IDC_EDIT_TX,m_strOut);
UpdateData(TRUE);
GetDlgItemText(IDC_EDIT_JSHA,m_jsha);
//填充SM_PARAM结构体内容
SM_PARAM smParam;
smParam=CreateSM_PARAM(m_jsha,m_strOut);
我要利用CreateSM_PARAM函数把变量m_jsha,m_strOut分别放进char TPA[16]; char TP_UD[161]; 该怎么做?
SM_PARAM CreateSM_PARAM (CString m_jsha,CString m_strOut)
{
SM_PARAM *p;
p=NULL;
p = new SM_PARAM();
p->TPA = m_jsha;
p->TP_UD = m_strOut;
return *p;
}
我这样编写提示出错 展开
1个回答
展开全部
具体代码参考如下:
SM_PARAM CreateSM_PARAM (CString m_jsha,CString m_strOut)
{
//定义和申请空间写一起
SM_PARAM *pSM = new SM_PARAM();
//结构体初始化‘0x00’
::memset(pSM, 0X00, sizeof(SM_PARAM));
//拷贝CString字符串数据到结构体
strcpy(pSM->TPA, (LPCTSTR)m_jsha);
strcpy(pSM->TP_UD, (LPCTSTR)m_strOut);
//提醒,由于返回的*pSM是堆上的空间,需要在外边释放.
return *pSM;
}
更多追问追答
追问
谢谢,还有我想问下我的那个SM_PARAM结构体是定义在comm.h里的,我在asscomm.cpp中执行
m_list.AddString(CString(smsNum[i].TPA)+smsNum[i].TP_UD);操作,
出现错误left of '.TPA' must have class/struct/union type
我应该怎么去编译?
追答
smsNum[i]
是什么类型?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询