Since this problem is only occurring when you are using Visual C++, I would venture to say that the problem lies with Visual C++. This is especially evident since the program runs without problem when it is a standalone executable.
I would suggest trying to uninstall and reinstall the Visual Studio development environment. I would also try to see if this problem is occurring on another machine. If it works on the development environment of the other machine, then your other computer may need a software overhaul (reinstall OS and development software).
If you are still having problems with this after trying these suggestions, feel free to contact National Instruments Support at www.ni.com/ask.
Good Luck!
Mike Rakolta
Applications Engineer
Nation
al Instruments
www.ni.com/ask