We recently had a customer with a Windows 7 PC that repeatedly crashed every couple of weeks due to memory and handle leaks in the Windows audio driver as described here.
http://support.microsoft.com/kb/981013
http://support.microsoft.com/kb/2670667
How did the customer respond when it occurred? If the customer cycled the power then that's catastrophic hardware failure and (almost) all bets are off. NTFS journaling should keep the directory structure intact, and possibly (probably?) the file allocation tables intact. But pending file content may not have been committed (even if it was committed by the OS and the hard drive returned success, the hard drive firmware may have deferred the actual write for performance reasons and it may still have gotten lost -- yes, hard drives do that these days to boost their throughput numbers).
Does anyone have any knowledge or experience of what can happen when Windows runs out of memory or handles? Can just about anything occur e.g. random corruption to the hard drive?
"Random" corruption seems very unlikely to happen at the OS level. I've certainly never encountered that on any combination of hardware or machines I've used or serviced that ran out of system resources. Which is around 20+ times on various combinations. I've seen several times where running out of system resources resulted in exposing app bugs, though they were sometimes not entirely obvious to track down. And I've seen many, many cases where an app hits out of disk or out of storage errors and didn't have proper transactional integrity and got stuck in a corrupted state (when the OS hadn't run out of resources -- e.g. on Win32 x86 where the OS still has more than 1.5GB shared address space available to it but an app blew out its private 2GB address space, or filled up the disk).
While it's possible for the OS to have a bug there, in my experience it's _always_ been mistakes in app code (or driver code!), not in core OS code.
If an application is continually writing data to a log file which is in a database and the application and database engine correctly check for memory allocation failure and API call errors, is it still possible that the database can become corrupted when Windows runs out of memory or handles?
"correctly check" seems like a key phrase here. Does any of the error handling path make any calls of any kind that could possibly ever fail? Probably yes. And if so, then the error handling code may not be fully robust in the presence of certain types of errors. And that could potentially lead to unpredictable things going wrong.
I'd recommend to examine the nature of the corruption, cross reference it with app code, and reverse engineer how it could occur. Pay extra attention to sequences of writes, as if a sequence of writes gets interrupted by an error then the storage may be left in an inconsistent state if the error handling and transactional logic isn't just right.
That might not be the cause here, but it's by far the most common cause in my experience. I think my experience is greater than average, but this certainly isn't a core area of expertise for me.
Hope that helps!