
Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX
Public Class Form1
Private Const PROCESS_ALL_ACCESS As Long = &H1FFFFF
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Integer, ByRef lpdwProcessId As Integer) As Integer
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Integer, ByVal bInheritHandle As Integer, ByVal dwProcessId As Integer) As Integer
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Integer) As Integer
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Integer
#Region " CaptureScreenshot ... "
Public Shared Function CaptureScreenshot(ByVal Device As Direct3D.Device, ByVal Filename As String, ByVal ImageFormat As Direct3D.ImageFileFormat) As Boolean
Dim Ssurface As Direct3D.Surface
Ssurface = Device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
Direct3D.SurfaceLoader.Save(Filename, ImageFormat, Ssurface)
Ssurface.Dispose()
Return True
End Function
Public Shared Function CaptureScreenshot(ByVal Device As Direct3D.Device, ByVal Filename As String) As Boolean
Return CaptureScreenshot(Device, Filename, Direct3D.ImageFileFormat.Bmp)
End Function
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim hWnd As Object, processHandle As IntPtr, processId As Integer
hWnd = FindWindow(vbNullString, "Call of Duty 4")
If (hWnd = 0) Then
MsgBox("Call of Duty 4! Not Found!", MsgBoxStyle.OkOnly, "Erorr!")
End
End If
GetWindowThreadProcessId(hWnd, processId)
processHandle = OpenProcess(PROCESS_ALL_ACCESS, False, processId)
Dim Dev As Direct3D.Device = New Direct3D.Device(processHandle)
CaptureScreenshot(Dev, "c:\Screenshott1.jpg", ImageFileFormat.Jpg)
CloseHandle(processHandle)
End Sub
End Class


System.*********enceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Microsoft.DirectX.Direct3D"
StackTrace:
at Microsoft.DirectX.Direct3D.Device.GetBackBuffer(Int32 swapChain, Int32 backBuffer, BackBufferType backBufferType) at WindowsApplication1.Form1.CaptureScreenshot(Device Device, String Filename, ImageFileFormat ImageFormat) in C:\Users\Siavash\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 12 at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Users\Siavash\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb:line 32 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
InnerException:
What line is highlighted when the code breaks during a debug......
In order for us to help you, run debug then when you get the error, a part of the code will be highlighted , what is that code(
