Click here to Skip to main content
15,917,793 members
Home / Discussions / Mobile
   

Mobile

 
Generalprinting to a text file...HELP PLEASE Pin
rodneyk131-Mar-04 8:51
rodneyk131-Mar-04 8:51 
I have created an MFC app and I am using the code that you have on the web to read and write. the first problem is

1. I think from a combo box you can only read the info as a CString (is that right?)and then I pass it to the readFile method and when I do all the casting to try to get it to write the string it only prints the first letter. Can you si what I am doing wrong?

do you have suggestions?

//Get current selections from edit and list-box controls
CString szChoice;
CString szResult;
int nChoice;
m_name.GetWindowText( szChoice);
nChoice = m_name.GetCurSel();
//if(nChoice!=CB_ERR)
{
//if a valid choice was made from the list box, fetch
//the item's text string.
m_name.GetLBText(nChoice,szChoice);
szResult="Closing after selecting "+ szChoice;
fileRead(L"\\My Documents\\my_file.txt",szChoice);
}

void fileRead(TCHAR *szFileName, CString szChoice)
{

hFile = CreateFile(szFileName, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
//if (hFile != INVALID_HANDLE_VALUE)
{
// Note that we are writing a string, not a unicode string

LPTSTR p = szChoice.GetBuffer( 10 );//not sure if this is nessecary
wcscpy( p, L"Name: "+(szChoice)); //copying szChoice into p so I can cast(what else should I do)?

szChoice.ReleaseBuffer( );//not sure about this it was in a EVC example(What is it?)
const char *val = reinterpret_cast<const char="" *="">(p);//Casting p into a 'char' so I can print to file
//so I could try to use strcpy
AfxMessageBox (p); //gives the whole string (name:Rod) it i typed rod in combo box
strcpy(buffer2, val);//copying val into buffer 2
strcpy(buffer1, "Hello dude" );//copying string "hello dude" into buffer
WriteFile(hFile, buffer1, strlen(buffer), &dwBytesWritten, 0);//writing to file"hello dude
WriteFile(hFile, buffer2, (szChoice.GetLength()), &dwBytesWritten, 0);//*********Only writes first letter'N' I want it
//to write 'Name: Rod', what do I have to do?

CloseHandle(hFile);
}

hFile = CreateFile(L"\\My Documents\\my_file.txt", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
}

I don't get it!!!!! When I switch the order that the buffers write, say write buffer 2 first then it only writes "N" and never gets to writing buffer1, if I write the buffer1 first it writes "hello dudeN". It is like when it gets to buffer2 it stops running and will only write one charactor.
GeneralRe: printing to a text file...HELP PLEASE Pin
Jonas Larsson6-Apr-04 3:40
Jonas Larsson6-Apr-04 3:40 
GeneralNewbie Looking for Help Pin
tracymc31-Mar-04 8:17
tracymc31-Mar-04 8:17 
GeneralRe: Newbie Looking for Help Pin
João Paulo Figueira31-Mar-04 22:05
professionalJoão Paulo Figueira31-Mar-04 22:05 
GeneralShell execute vs. Create Process Pin
RB@Emphasys31-Mar-04 8:02
RB@Emphasys31-Mar-04 8:02 
GeneralRe: Shell execute vs. Create Process Pin
Daniel Strigl31-Mar-04 19:40
Daniel Strigl31-Mar-04 19:40 
Generalaccess PocketPC files from PC Pin
badzio31-Mar-04 2:09
badzio31-Mar-04 2:09 
GeneralRe: access PocketPC files from PC Pin
João Paulo Figueira31-Mar-04 3:40
professionalJoão Paulo Figueira31-Mar-04 3:40 
GeneralADO Sample Pin
arlevand30-Mar-04 21:51
arlevand30-Mar-04 21:51 
GeneralRe: ADO Sample Pin
João Paulo Figueira31-Mar-04 0:19
professionalJoão Paulo Figueira31-Mar-04 0:19 
GeneralBluetooth connection...... Pin
Deepa Gopal29-Mar-04 20:36
Deepa Gopal29-Mar-04 20:36 
GeneralProblem with Virtual List View Pin
Bui Huy Kien29-Mar-04 18:06
Bui Huy Kien29-Mar-04 18:06 
GeneralRe: Problem with Virtual List View Pin
Daniel Strigl29-Mar-04 19:00
Daniel Strigl29-Mar-04 19:00 
GeneralRe: Problem with Virtual List View Pin
João Paulo Figueira29-Mar-04 21:04
professionalJoão Paulo Figueira29-Mar-04 21:04 
GeneralRe: Problem with Virtual List View Pin
Bui Huy Kien29-Mar-04 22:17
Bui Huy Kien29-Mar-04 22:17 
GeneralRe: Problem with Virtual List View Pin
João Paulo Figueira29-Mar-04 22:28
professionalJoão Paulo Figueira29-Mar-04 22:28 
GeneralRe: Problem with Virtual List View Pin
Bui Huy Kien30-Mar-04 1:00
Bui Huy Kien30-Mar-04 1:00 
QuestionHow To Localize the Menu??? Pin
Rassul Yunussov29-Mar-04 0:22
Rassul Yunussov29-Mar-04 0:22 
AnswerRe: How To Localize the Menu??? Pin
João Paulo Figueira29-Mar-04 1:59
professionalJoão Paulo Figueira29-Mar-04 1:59 
GeneralRe: How To Localize the Menu??? Pin
Rassul Yunussov29-Mar-04 6:08
Rassul Yunussov29-Mar-04 6:08 
GeneralRe: How To Localize the Menu??? Pin
João Paulo Figueira29-Mar-04 6:14
professionalJoão Paulo Figueira29-Mar-04 6:14 
General[eVC] Internationalization and Multiple Language Support Pin
GuilhemMtp28-Mar-04 22:10
GuilhemMtp28-Mar-04 22:10 
GeneralMultiple forms in mobile web application Pin
Weiye Chen28-Mar-04 16:21
Weiye Chen28-Mar-04 16:21 
Generalneed help Pin
monn27-Mar-04 5:43
monn27-Mar-04 5:43 
GeneralPocket PC 2002 network programming Pin
democls26-Mar-04 11:07
democls26-Mar-04 11:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.