Problem GetBackBuffer

Posts 1–15 of 24 · Page 1 of 2
Problem GetBackBuffer
Hi Everyone!
pls help me for fix my problem
Code:
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
Don't Work Don't Wrok
Copy & paste code you don't understand usually leads to problems.
Quote Originally Posted by Blubb1337 View Post
Copy & paste code you don't understand usually leads to problems.
sory
im run game cod4 and run my program for take screenshoot then
erorr line
Code:
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:
Sory For my bad english
yah. whats ur prob ? its hard for us to find the problem inn all this xD
Can you explain to me what the code does?

Also, use Google translator to speak if you have bad English.
The code is code for taking a screenshot and saving it. Which line gives you the error, Once we get there, use try and catch to catch the actual error, but we may be able to figure it out when we know which line it is
Quote Originally Posted by NextGen1 View Post
The code is code for taking a screenshot and saving it. Which line gives you the error, Once we get there, use try and catch to catch the actual error, but we may be able to figure it out when we know which line it is
Hi Yes, the code for taking pictures in the game environment written. But when the play when I want to get a photo gives me error. I do not know where the problem for what it gives this error Please help me
Quote Originally Posted by HeadHunter666 View Post
Hi Yes, the code for taking pictures in the game environment written. But when the play when I want to get a photo gives me error. I do not know where the problem for what it gives this error Please help me
As NextGen said, wrap the code that's screwing up in a try-catch block like so

[php]

Try
// add code that gives you errors here
Catch ex As Exception
MsgBox("Error occurred: " & ex.Message)
End Try
[/php]

And then post the returned error here so we actually get an idea of what's wrong.
Quote Originally Posted by Jason View Post


As NextGen said, wrap the code that's screwing up in a try-catch block like so

[php]

Try
// add code that gives you errors here
Catch ex As Exception
MsgBox("Error occurred: " & ex.Message)
End Try
[/php]

And then post the returned error here so we actually get an idea of what's wrong.
I've used your code and I received a message
Erorr occurred:Object refrence not set to an instance of an object
So, in your opinion where is my problem
I'm tired I'm tired of that really solve this please help thank s
Okay remove the Try-Catch and let it crash, then tell me exactly what line is being highlighted with yellow and telling you there is an error.
Quote Originally Posted by Jason View Post
Okay remove the Try-Catch and let it crash, then tell me exactly what line is being highlighted with yellow and telling you there is an error.
highlighted code
Code:
Ssurface = Device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
Well, if I wanted all my pure mathematical formula to solve the no problem. I kidding
I more than ten times the error code I gave you realize you're not
I'm really tired
That didn't help at all 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(
your a leecher

/
Watch the flame.
Please Stop spam.
Well someone help me or not s
Posts 1–15 of 24 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?