0

I am trying to read items from CListBox and writing to a file using CFile.

Here is my code

int count = m_lstSelectedItems.GetCount();

CFile cfile_object;
cfile_object.Open( L"C:\\temp.txt",  CFile::modeCreate|CFile::modeReadWrite);

for(int i=0; i<count; ++i)
{       
    int n;
    LPTSTR s2 = new TCHAR[256];
    memset(s2, 0, 256);

    n = m_lstSelectedItems.GetTextLen(i);       
    m_lstSelectedItems.GetText(i, s2);

    cfile_object.Write (s2, n);     
    cfile_object.Write("\n",2);

    delete[] s2;
}

cfile_object.Close();

But I am getting this data

 F:\Programs\Test\SelectDialo੧䘀㨀尀倀爀漀最爀愀洀猀尀吀攀猀琀尀匀攀氀攀挀琀䐀椀愀氀漀最开

Any suggestions to get correct data.

Thanks

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
atulya
  • 535
  • 2
  • 8
  • 25

1 Answers1

0

Able to solve it using CT2CA function

int n;
CString str;

n = m_lstSelectedItems.GetTextLen(i);
m_lstSelectedItems.GetText(i,str);

CT2CA outputString(str, CP_UTF8);
cfile_object.Write(outputString, ::strlen(outputString));
cfile_object.Write("\n",1);

http://msdn.microsoft.com/en-us/library/87zae4a3(VS.80).aspx

atulya
  • 535
  • 2
  • 8
  • 25