I Managed to solve this problem. This error has to some with DEP compatibility. The program is generating DEP exceptions and to clear it we have to clear IMAGE_DLLCHARACTERISTICS_NX_COMPAT flag.
This can be done by adding post build event in Visual Studio
call $(DevEnvDir)..\tools\vsvars32.bat editbin.exe /NXCOMPAT:NO $(TargetPath)
Refer stack over flow question How to make my program DEP-compatible?