Firstly, there is an error in your code, a tip: it is to do with something that you did which uses the StdAfx library. Secondly, Im not going to read through all that code to find it. Just look in your functions, somewhere you will find the error, maybe AfxMessageBox or something like that, just do a search for anything starting with Afx.

Hope this helps