I have a VS2008 project, unmanaged code, using MFC. Actually a legacy project that I am adding support for Volume Shadow Copy (VSS services). The code is running and almost complete but I need to add some threads to boost performance. When I run a VSS function in the same thread as the main program, the call:
HRESULT hr2=m_pVssObject->InitializeForBackup();
works as expected, but that same call, in the same function, fails when run in a separate thread. When that statement is executed in the separate thread, the debugger output windows shows:
'program.exe': Loaded 'C:\Windows\System32\samlib.dll'
First-chance exception at 0x7721b09e in program.exe: Microsoft C++ exception: long at memory location 0x017cfa74..
and the HRESULT is E_UNEXPECTED. The event log shows that the VSS Service failed to start (which caused the E_UNEXPECTED).
When the function is run in the main thread, there is no failure and the output window shows:
'program.exe': Loaded 'C:\Windows\System32\samlib.dll'
'program.exe': Loaded 'C:\Windows\System32\clbcatq.dll'
'program.exe': Loaded 'C:\Windows\System32\msxml3.dll'
'program.exe': Loaded 'C:\Windows\System32\rsaenh.dll'
'program.exe': Loaded 'C:\Windows\System32\vss_ps.dll'
There are no errors, and a VSS snapshot is taken. Life is good.
Further, as a workaround, if I call:
HRESULT hr =CreateVssBackupComponents(&m_pVssObject) ;
and
HRESULT hr2=m_pVssObject->InitializeForBackup();
before starting the thread, all works OK when the thread is started and the same API's are called again.
(m_pVssObject is declared as a pointer to IVssBackupComponents )
It seems that something is failing causing the "First-chance exception" but I can't track it down. Any help appreciated.
Lou
Lou