Related to this question. Any advice on fixing the problem below?
After a lot of experimentation with the program, I have discovered several things.
It crashes relatively consistently (90% of the time or so) upon running the line of code,
Set Message = New CAPICOM.EncryptedData
. Note that the line above this is merelyDim Message As CAPICOM.EncryptedData
.The function that makes that call does not crash when called earlier in the program's execution. Binary search for error does not work to find the problem, since calling the function in some places mysteriously, unreliably prevents the bug from happening. Sometimes rebuilding the program seems to impact if the bug shows up. Yes, it is a heisenbug. The same issues apply with temporal binary search for error. Spending 5 hours comparing two versions of the program only to discover that both versions have the bug even though only one of them is currently showing the symptoms is not very productive.
The crash is due to an access violation 0xC00000005
Running WinDbg (the windows debugger) shows that there is only one line of code which reads this memory location,
LoadPicture(szTmpBMP)
. It is called at the end of a scary function which grabs the picture out of a resource and sticks it in a temp file. I was scared enough of this function that, for the sake of testing, I replaced it with a call toLoadPicture("testcra.bmp")
, then didn't call the scary resource function for that bitmap. This did not help. Removing this call to loadpicture entirely also did not help, though the debugger could no longer find any points where the affected memory was being read, and the affected memory was no longer at the same location. This testing was done on a VM, so some memory reads are not necessarily going to be visible to the debugger.Everything works perfectly on Vista (both my local machine and a Vista VM). The access violation only occurs on XP.
I'm using VB6 Version 8176, 6.0.8169