Click here to Skip to main content
15,925,868 members
Home / Discussions / Mobile
   

Mobile

 
GeneralHelp !!! Problem in calling webservice from PocketPC Pin
Anonymous31-Mar-04 23:21
Anonymous31-Mar-04 23:21 
QuestionQuick Question... Internet? Pin
Anonymous31-Mar-04 12:56
Anonymous31-Mar-04 12:56 
Questionhow to go from CString to char [] Pin
rodneyk131-Mar-04 10:27
rodneyk131-Mar-04 10:27 
AnswerRe: how to go from CString to char [] Pin
Daniel Strigl31-Mar-04 19:43
Daniel Strigl31-Mar-04 19:43 
GeneralRe: how to go from CString to char [] Pin
rodneyk12-Apr-04 4:31
rodneyk12-Apr-04 4:31 
GeneralRe: how to go from CString to char [] Pin
Daniel Strigl2-Apr-04 19:03
Daniel Strigl2-Apr-04 19:03 
Generalprinting to a text file...HELP PLEASE Pin
rodneyk131-Mar-04 8:51
rodneyk131-Mar-04 8:51 
GeneralRe: printing to a text file...HELP PLEASE Pin
Jonas Larsson6-Apr-04 3:40
Jonas Larsson6-Apr-04 3:40 
rodneyk1 wrote:
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)?


First, this is bad. GetBuffer(10) guarantees you space for atleast 10 characters (20 bytes if UNICODE is defined, 10 otherwise), but you have no idea about the upper limit. Your second line can produce a buffer overrun. A safer way to do this is:
szChoice = L"Name: " + szChoice;
LPTSTR p = szChoice.GetBuffer( 10 );
Although I wouldnt recommend it either.

rodneyk1 wrote:
const char *val = reinterpret_cast(p);//Casting p into a 'char' so I can print to file

The template argument to reinterpret_cast was lost, but Im guessing that you had char* or const char* there.

The deal is that just because you can cast a LPTSTR variable (which stands for long pointer to T string, ie wchar_t* on wince) to a const char* variable does not convert the data pointed to by said variable to char's.


rodneyk1 wrote:
strcpy(buffer2, val);//copying val into buffer 2
(I dont see where you declare buffer2, but I will assume it's declared as char buffer2[255]; )

So, here we have val (const char*), which is pointing to the same memory area as p (wchar_t*), which points to whatever memory szChoice.GetBuffer() provides (also wchar_t*).
So, if we examine the memory that val points to, it should look something like:
'N', 0, 'a', 0, 'm', ...
which means that strcpy will grab the first character and then reach the 0-terminator => strcpy appends a \0 to buffer2 and then return.


rodneyk1 wrote:
WriteFile(hFile, buffer2, (szChoice.GetLength()), &dwBytesWritten, 0);

Here, WriteFile will write 'N', 0 and then whatever garbage that buffer2 contains after the 0, until it has written szChoice.GetLength() characters. You can examine your file in a hex-editor to see what it has written, possibly all 0's after the 'N', depending on how buffer2 was declared.


In short, you should read up on WideCharToMultiByte, and also look into fixing your memory managent issues.

HTH
Jonas



---

“Our solar system is Jupiter and a bunch of junk” - Charley Lineweaver 2002
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 

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.