Crash in nvinit.dll_unloaded when application closes

We have written an application for screen capturing. However, on Nvidia laptops with the Optimus technology, the application crashes in nvinit.dll_unloaded when it closes. The crash can be avoided if the user sets the preferred graphics processor drop-down to “High-performance NVIDIA processor” in the Nvidia configuration dialog. When I Google for this problem, I see that a lot of other applications experience the same crash when being closed (but no real solution was found). What could be the cause for this and is there a way to solve this without asking the user to turn off the ‘auto select graphics card’ option?

Dump from event viewer (detailed dump attached)
Faulting application name: screencap.exe, version:, time stamp: 0x50edc5e7
Faulting module name: nvinit.dll_unloaded, version:, time stamp: 0x506b31f3
Exception code: 0xc0000005
Fault offset: 0x7534ce39
Faulting process id: 0xbb0
Faulting application start time: 0x01cdef4e5c615f70
Faulting application path: F:\screencap.exe
Faulting module path: nvinit.dll
Report Id: 93dbc150-5b43-11e2-b76a-20689d5ddd7b

+1 to this post, I’ve posted a thread about this as well.