list and ip control in mfc
-
hello, i want to copy the content of ip control and add it to a list control. so try to do this ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, LPCTSTR(m_M1));}
it compiles without any error but when i run it and click ok, it shows the error ---
Unhandled exception at 0x746bc348 in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x00000017.
i also tried ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, (LPCTSTR)ss);}
error ---
Unhandled exception at 0x5cd3e9ee (msvcr90d.dll) in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x0000006f.
i also tried something like this which is working without any problem ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, _T("ABC"));}
please help.
-
hello, i want to copy the content of ip control and add it to a list control. so try to do this ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, LPCTSTR(m_M1));}
it compiles without any error but when i run it and click ok, it shows the error ---
Unhandled exception at 0x746bc348 in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x00000017.
i also tried ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, (LPCTSTR)ss);}
error ---
Unhandled exception at 0x5cd3e9ee (msvcr90d.dll) in server_side_mfc.exe: 0xC0000005: Access violation reading location 0x0000006f.
i also tried something like this which is working without any problem ----
void Cserver_side_mfcDlg::OnBnClickedOk2()
{
BYTE m_M1, m_M2, m_M3, m_M4;
DWORD s = 0;
char ss[20] = {0};
UpdateData();
m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4);
m_ipList.InsertItem(s++, _T("ABC"));}
please help.
rahuljin wrote:
void Cserver_side_mfcDlg::OnBnClickedOk2() { BYTE m_M1, m_M2, m_M3, m_M4; DWORD s = 0; char ss[20] = {0}; UpdateData(); m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4); sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4); m_ipList.InsertItem(s++, (LPCTSTR)ss); }
You cannot simply typecast a char to LPCTSTR. So use TCHAR ss[20] instead.
«_Superman_» I love work. It gives me something to do between weekends.
-
rahuljin wrote:
void Cserver_side_mfcDlg::OnBnClickedOk2() { BYTE m_M1, m_M2, m_M3, m_M4; DWORD s = 0; char ss[20] = {0}; UpdateData(); m_ipAdd.GetAddress(m_M1, m_M2, m_M3, m_M4); sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4); m_ipList.InsertItem(s++, (LPCTSTR)ss); }
You cannot simply typecast a char to LPCTSTR. So use TCHAR ss[20] instead.
«_Superman_» I love work. It gives me something to do between weekends.
-
thanks. but then how will i use ---
sprintf_s(ss, "%s:%s:%s:%s", m_M1, m_M2, m_M3, m_M4);
_stprintf_s(ss, _T("%d:%d:%d:%d"), m_M1, m_M2, m_M3, m_M4);
«_Superman_» I love work. It gives me something to do between weekends.