Originally Posted by
J-Deezy
You never assigned a value to the integer "ProcessId" in this section of the code:
[php]
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
[/php]
You declared processID but never got the value for it.
Try adding this function to your code
[php]
Private Function GetPID(ByVal ProcName As String)
If ProcName.Contains(".") Then
ProcName = ProcName.Substring(0, ProcName.LastIndexOf("."))
End If
Dim PID As Integer = 0
For Each p As Process In Process.GetProcesses(My.Computer.Name)
If p.ProcessName = ProcName Then
PID = p.Id
End If
Next
Return PID
End Function
[/php]
and then change the original code to:
[php]
Dim hWnd As Integer, processHandle As IntPtr, processId As Integer
ProcessID = GetPID("CoD process name as seen in task manager without .exe")
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)
[/php]
I dunno if that will fix your problem seeing as I've never really worked with DirectX, but not assigning the ProcessID any value doesn't seem like a good start -.-
You'll need to change this line here:
[php]
ProcessID = GetPID("CoD process name as seen in task manager without .exe")
[/php]
Where i've put "CoD process name as seen in task manager without .exe" you'll need to do just that, I didn't know the CoD process name. Example would be for Combat Arms, the process name is "Engine" (note, don't include the exe)
Tell me if that changes anything.