First we had the monitor Brightness Thread, now we have this interesting thread. OK, enough about me
This is possible through the MiniDumpWriteDump API available inside the dbghelp.dll file.
Its signature looks like this :
Code:
'Dump API
<DllImport("dbghelp.dll")> _
Private Shared Function MiniDumpWriteDump(ByVal hProcess As IntPtr, _
ByVal ProcessId As Int32, _
ByVal hFile As IntPtr, _
ByVal DumpType As DumpTypes, _
ByVal ExceptionParam As IntPtr, _
ByVal UserStreamParam As IntPtr, _
ByVal CallackParam As IntPtr) As Boolean
I quickly slapped something together for you It takes the current process, and writes the dump information into a file called C:\dumped.txt. Here is the full code :
Code:
Imports System.Diagnostics
Imports System.IO
Imports System.Runtime.InteropServices
Public Class Form1
'Dump API
<DllImport("dbghelp.dll")> _
Private Shared Function MiniDumpWriteDump(ByVal hProcess As IntPtr, _
ByVal ProcessId As Int32, _
ByVal hFile As IntPtr, _
ByVal DumpType As DumpTypes, _
ByVal ExceptionParam As IntPtr, _
ByVal UserStreamParam As IntPtr, _
ByVal CallackParam As IntPtr) As Boolean
End Function
'Various Dump Types
Enum DumpTypes
DumpNormal = 0
DumpWithDataSegs = 1
DumpWithFullMemory = 2
DumpWithHandleData = 4
DumpFilterMemory = 8
DumpScanMemory = 10
DumpWithUnloadedModules = 20
DumpWithIndirectlyReferencedMemory = 40
DumpFilterModulePaths = 80
DumpWithProcessThreadData = 100
DumpWithPrivateReadWriteMemory = 200
DumpWithoutOptionalData = 400
DumpWithFullMemoryInfo = 800
DumpWithThreadInfo = 1000
DumpWithCodeSegs = 2000
End Enum
Private Sub DumpToFile(ByVal DumpFile As String)
'Create An IO Stream
Dim ProcDumpFile As IO.FileStream = Nothing
'Check Existance
If (IO.File.Exists(DumpFile)) Then
ProcDumpFile = IO.File.Open(DumpFile, IO.FileMode.Append)
Else
ProcDumpFile = IO.File.Create(DumpFile)
End If
'Get Current Process
'Here You Could Get Another Process
Dim ProcToDump As Process = Process.GetCurrentProcess()
'Get Dump Info
'And Write Dump Info
MiniDumpWriteDump(ProcToDump.Handle, _
ProcToDump.Id, _
ProcDumpFile.SafeFileHandle.DangerousGetHandle(), _
DumpTypes.DumpNormal, _
IntPtr.Zero, _
IntPtr.Zero, _
IntPtr.Zero)
'Close File
ProcDumpFile.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Call Sub To Write Dump Info
'Into C:\Dumped.txt
DumpToFile("C:\Dumped.txt")
End Sub
End Class
I am attaching a full working project here for you ( as a .zip file ). This code should work in VB 2005 and 2008 as well. As I've said, you could use a different process as well, instead of the current process, but this should help you get organised
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.