Unexplained "unhandled exception"
This "unhandled exception" case is unexplained. The behavior of a loop is unexplained as well.
The place where I set Text to zero is where the "unhandled exception" notice comes from. Text is a string supporting 1023 main characters and an extra for the null character. In case I use a string that is unexpectedly too long, I set Text to zero to ensure I get the null character. When defining an array, the highest value that can be used is one less than that defined. That is:
void DrawBMPFont(char Text, short StartX, short StartY, short width, int XBorder, int YBorder)
... // notes and local variables
if (Text != 0) // if last possible character is not null
Text = 0; // the null character must be enforced.
... // the rest of the function
I can use sample just fine but not sample. Why is it giving the "unhandled exception" notice here? The array is 1024 long and the one accessed is within the range at 1023. If it was 1024, I can understand that, but this is 1023....
If I comment the if statement out, another strange problem occurs.
This loop is going on infinitely, one reason for the LoopCount stuff - to break the loop in case it's infinite making it easier to close the program. The string being passed to the function is "SampleString" without spaces. That's just 12 characters and the last one would be Text for the array. By the twelfth loop, using Text, the string has been terminated and the null character is present. I'm also surprised I'm not getting the "unhandled exception" notice as the array index keeps increasing for each loop and it goes far beyond 1023 as the value. Accessing Text when only 1024 is present will definitely cause problems, but strangely it isn't. What's going on here? In case you're wondering, it's to display a bitmap font, as a TGA image. This is basic C stuff and thus not Windows-related.
while ((Text[ArrayIndex] != TextSpace) || (Text[ArrayIndex] != 0x0A) || (Text[ArrayIndex] != 0)) // loop until a space or line feed is encountered
PosX += Font.CharWidth[Text[ArrayIndex]]; // add the character's width
LoopCount++; // debugging only
if (LoopCount >= 10000000) // ten million loops is way too many
sprintf(DebugDetails, "Warning: an infinite loop in the first loop is present!"); // for debugging
MessageBox(hwnd, DebugDetails, "Debug Results", MB_OK);
break; // terminate the function regardless of the function's success
if (LoopCount >= 10000000)
break; // break the main loop