Vb.net 接口成员的未定义行为

Vb.net 接口成员的未定义行为,vb.net,interface,directx,Vb.net,Interface,Directx,故事是这样的: < >我想从DIRTIX 10 C++代码中生成VB.NET代码,函数代码d3dx10CealDeice和SavaPhanIn()/Cuth>与我工作良好: Public Declare Function D3DX10CreateDeviceAndSwapChain Lib "d3dx10_43.dll" _ (ByVal pAdapter As IDXGIAdapter, ByVal drivertype As D3D10_DRIVER_TYPE,

故事是这样的:

< >我想从DIRTIX 10 C++代码中生成VB.NET代码,函数<>代码d3dx10CealDeice和SavaPhanIn()/Cuth>与我工作良好:

Public Declare Function D3DX10CreateDeviceAndSwapChain Lib "d3dx10_43.dll" _
    (ByVal pAdapter As IDXGIAdapter,
     ByVal drivertype As D3D10_DRIVER_TYPE,
     ByVal software As IntPtr,
     ByVal flags As UInteger,
     ByRef pswapchaindesc As DXGI_SWAP_CHAIN_DESC,
     ByRef ppSwapChain As IntPtr,
     ByRef ppDevice As IntPtr) As Integer`
代码的其余部分是:

Dim swapChainDesc As New DXGI_SWAP_CHAIN_DESC()
    swapChainDesc.BufferCount = 1
    swapChainDesc.BufferDesc.Width = Me.Width
    swapChainDesc.BufferDesc.Height = Me.Height
    swapChainDesc.BufferDesc.Format = DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM
    swapChainDesc.BufferUsage = 1L << (1 + 4) 
    swapChainDesc.OutputWindow = Me.Handle
    swapChainDesc.SampleDesc.Count = 1
    swapChainDesc.SampleDesc.Quality = 0
    swapChainDesc.Windowed = True


Dim sc As IntPtr
Dim d As IntPtr
D3DX10CreateDeviceAndSwapChain(Nothing,D3D10_DRIVER_TYPE.D3D10_DRIVER_TYPE_HARDWARE,IntPtr.Zero,0,swapChainDesc,sc,d)
在此之前,代码返回success

Dim rtv As ID3D10RenderTargetView
Dim hresult As Integer = device.CreateRenderTargetView(surface, Nothing, rtv)
surface.Release() ' this works fine
MsgBox(rtv IsNot Nothing)
问题是:

当我更改位置(将它们之间的成员排列到接口ID3D10Device中)时,我会得到AccessViolationException或 该行的异常 结果是

为什么会出现这种未定义的行为


备注:接口ID3D10Device包含80多个成员,我还更改了一些成员位置,它们工作正常。

首先,不要使用DirectX 10。这毫无意义。使用DirectX 11,因为它支持所有相同的平台,支持更多的硬件,并且通常由工具和库更好地支持。其次,编写自己的托管程序集来包装DirectX是一项相当具有挑战性的工作。我建议你看看或。避免使用旧版托管DirectX 1.1程序集。有什么想法吗。
Dim rtv As ID3D10RenderTargetView
Dim hresult As Integer = device.CreateRenderTargetView(surface, Nothing, rtv)
surface.Release() ' this works fine
MsgBox(rtv IsNot Nothing)