I'm working through Petzold "Programming Windows" 5th edition, using Visual Studio 2015 Community Edition on a Windows 8.1 machine, and having problems with the PoePoem program on p. 432-437.
The program will compile, but throws an exception on execution.
Apparently, in the WM_CREATE
message processing, while I can load the text of the poem as a resource and count the number of lines, the debugger reports an access violation in the last line of this code snippet when I attempt to write a '\0'
character in place of the backslash '\\'
.
Evidently things have changed sufficiently in 20 years that the program as written no longer works. Is there a workaround?
hResource = LoadResource (hInst,
FindResource (hInst, TEXT ("AnnabelLee"),
TEXT ("TEXT"))) ;
pText = (char *) LockResource (hResource) ;
iNumLines = 0 ;
while (*pText != '\\' && *pText != '\0')
{
if (*pText == '\n')
iNumLines ++ ;
pText = AnsiNext (pText) ;
}
*pText = '\0' ;
I had a long wrestle with Visual Studio to get proper construction of the *.rc files and resource.h files, omitted the hInst declaration, misspelled the text several times. I finally got the program to compile, but I'm still missing something.