It seems like you've missed the left parenthesis when casting CMainDlg. But other than that, it looks like it should work...

"atlsimpstr.h" indicates that a string is used somewhere. Did you leave out any code that is running inside the while loops?