Closed yanpeng closed 1 year ago
Hi,
I'm currently on vacation, so I'll look at this as soon as I can.
Actually, I think this is a modification that I did, because the original version crashed on line 108. This is because resources are immutable in memory, although the sample apparently worked back when it was first written.
I think line 108 could probably be deleted, but I'd have to test it first.
Actually, I think this is a modification that I did, because the original version crashed on line 108. This is because resources are immutable in memory, although the sample apparently worked back when it was first written.
I think line 108 could probably be deleted, but I'd have to test it first.
oh, sorry for bothering. yeah, if *pText = '\0'
, it would crash the program, the reason is what you said above (Visual Studio showed this error). But if we deleted this line, we have to calculate the length of the text (loaded by LockResource
) because we cannot guarantee the text ending with \0
. We also cannot pass -1
to cchText
of DrawTextA
, pass the length of the text instead.
Have a good holiday!!!
I've added a note explaining the change I did to clarify why it differs from the original sample. Thanks for your keen eye, as I had forgotten I had done this change.
Thanks for your archiving these codes. BTW, the afxres.h
in resource script should be replaced with winres.h
, or cannot compile the project on new version visual studio. (or that afxres.h
needs MFC component to be installed, but I never touched MFC.)
Yeah, that's mentioned in the readme under the "Building" category. I chose to leave it as I don't want to change the original samples too much if it can be avoided.
Hi,
bother you again...
Line 108
ofPoePoem.c
, it isThe same line of the book is
I think the latter is right. The type of
pText
ischar*
, the intention of the author is to replace the last\
with\0
. In this way, we make certain that the string we loaded into the memory is ending with\0
, so whenDrawTextA
inWM_PAINT
, we can pass-1
to thecchText
argument safely.In the text after this program, the author said:
After changing
pText = '\0'
to*pText = '\0'
, another problem arises: Visual C++ didn't allow to modify that piece of memory pointed bypText
.