Click here to Skip to main content
15,896,912 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Learning C++ Pin
ThatsAlok5-Aug-05 23:19
ThatsAlok5-Aug-05 23:19 
GeneralRe: Learning C++ Pin
Malthusian6-Aug-05 11:07
Malthusian6-Aug-05 11:07 
GeneralPlease help me! Pin
dSolariuM5-Aug-05 17:30
dSolariuM5-Aug-05 17:30 
GeneralCInternetFile: problem in reading remote file Pin
Aditya Rao5-Aug-05 16:59
Aditya Rao5-Aug-05 16:59 
GeneralRe: CInternetFile: problem in reading remote file Pin
Jose Lamas Rios5-Aug-05 17:17
Jose Lamas Rios5-Aug-05 17:17 
GeneralRe: CInternetFile: problem in reading remote file Pin
Aditya Rao5-Aug-05 18:00
Aditya Rao5-Aug-05 18:00 
GeneralRe: CInternetFile: problem in reading remote file Pin
sunit55-Aug-05 20:10
sunit55-Aug-05 20:10 
GeneralRe: CInternetFile: problem in reading remote file Pin
Jose Lamas Rios6-Aug-05 15:25
Jose Lamas Rios6-Aug-05 15:25 
Aditya Rao wrote:

CString str;
.
.
.
while( writebytes = pfile -> Read ( (void *)str.operator LPCTSTR(), 50 )!=0 )


Besides what sunit5 already told you about the way of using the operator (i.e.: you could just write (LPCTSTR)str instead of str.operator LPCTSTR()) I see a far worse problem in your code.

That operator returns a constant pointer to the internal buffer of the CString object. It stops being constant because you then cast it to a (void*), but that's not the problem, either. The first problem is that you don't know the size of that buffer, and can't be sure it has enough space to hold the 50 chars you are asking to put there. You might be causing a buffer overrun with code like that. For a buffer size as small of 50, you can just allocate it as follows:

const int nBufferSize = 50;
BYTE buffer[nBufferSize];

The second problem is the way you wrote the loop condition. The count of bytes read is being compared to 0, and the result of that comparison is then assigned to writebytes. I'm sure that's not what you meant to write. You need to add some parenthesis to change the order of evaluation.

So, try changing the loop to the following and see if that helps,

const int nBufferSize = 50;
BYTE buffer[nBufferSize];

while ((writebytes = pfile->Read((void *)buffer, nBufferSize)) != 0)
{
   fp.Write(buffer, writebytes);
}


Hope that helps,

On another note, please send your response, if any, posting again to the forum, and not by mail.


--
jlr
http://jlamas.blogspot.com/[^]
GeneralRe: CInternetFile: problem in reading remote file Pin
Aditya Rao6-Aug-05 16:55
Aditya Rao6-Aug-05 16:55 
GeneralRe: CInternetFile: problem in reading remote file Pin
Jose Lamas Rios6-Aug-05 17:12
Jose Lamas Rios6-Aug-05 17:12 
GeneralHiding CMenu items Pin
Ivan Cachicatari5-Aug-05 15:47
Ivan Cachicatari5-Aug-05 15:47 
GeneralRe: Hiding CMenu items Pin
ThatsAlok5-Aug-05 20:41
ThatsAlok5-Aug-05 20:41 
GeneralGive you the example: Pin
bghuang6-Aug-05 2:45
bghuang6-Aug-05 2:45 
GeneralGetConsoleWindow() Error C2065: Undeclared identifier Pin
chiyinhk5-Aug-05 14:33
chiyinhk5-Aug-05 14:33 
GeneralRe: GetConsoleWindow() Error C2065: Undeclared identifier Pin
Jose Lamas Rios5-Aug-05 17:01
Jose Lamas Rios5-Aug-05 17:01 
GeneralRe: GetConsoleWindow() Error C2065: Undeclared identifier Pin
ThatsAlok5-Aug-05 23:43
ThatsAlok5-Aug-05 23:43 
GeneralD3DXCreateTextureFromFile and CBitmap Pin
akira325-Aug-05 12:51
akira325-Aug-05 12:51 
Questionhow to create 2 splitters in a window (using MFC) Pin
/*Trucker*\5-Aug-05 11:21
/*Trucker*\5-Aug-05 11:21 
AnswerRe: how to create 2 splitters in a window (using MFC) Pin
GKarRacer5-Aug-05 12:00
GKarRacer5-Aug-05 12:00 
GeneralRe: how to create 2 splitters in a window (using MFC) Pin
/*Trucker*\5-Aug-05 13:03
/*Trucker*\5-Aug-05 13:03 
GeneralRe: how to create 2 splitters in a window (using MFC) Pin
GKarRacer5-Aug-05 13:32
GKarRacer5-Aug-05 13:32 
GeneralRe: how to create 2 splitters in a window (using MFC) Pin
/*Trucker*\5-Aug-05 14:05
/*Trucker*\5-Aug-05 14:05 
Generalgrid with comboboxes in CFormView Pin
Spiritofamerica5-Aug-05 11:10
Spiritofamerica5-Aug-05 11:10 
GeneralOpening system menu with code don’t work Pin
Patric_J5-Aug-05 10:27
Patric_J5-Aug-05 10:27 
GeneralRe: Opening system menu with code don’t work Pin
GKarRacer5-Aug-05 11:35
GKarRacer5-Aug-05 11:35 

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.