Microsoft.DirectX库INVALIDCALL错误

时间:2016-10-29 11:34:23

标签: vb.net directx

我使用Microsoft DirectX SDK为我的应用程序获取屏幕截图,并且我收到错误:

  

applcation出错。 ErrorString =" D3DERR_INVALIDCALL"

这是我的代码:

Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX

Private Function fGetMe() As Control
    If Me.InvokeRequired Then
        Me.Invoke(New fGetMeDelegate(AddressOf fGetMe))
       ' Return Me
    Else
        Return Me
    End If
End Function

Private Delegate Sub fGetMeDelegate()

Private Function sCaptureScreenDX() As Image
        Dim prp As PresentParameters = New PresentParameters()
        prp.Windowed = True
        prp.SwapEffect = SwapEffect.Discard
        Dim dvc As New Device(0, DeviceType.Hardware, fGetMe(), CreateFlags.SoftwareVertexProcessing, prp)
        Dim sur As Surface = dvc.CreateOffscreenPlainSurface(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8B8G8R8, Pool.Scratch)
        dvc.GetFrontBufferData(0, sur)
        Dim gs As GraphicsStream = SurfaceLoader.SaveToStream(ImageFileFormat.Bmp, sur)
        Dim bmp As New Bitmap(gs)
        Return CType(bmp, Image)
End Function
调用

fGetMe()是因为我使用多个线程并且需要线程安全回调。

我在SlimDX中尝试了这个,我得到了同样的错误。当我拨打dvc.GetFrontBufferData(0, sur)

时会发生这种情况

这是否有任何具体原因?

0 个答案:

没有答案