Imports microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Form1
Private dev As Microsoft.DirectX.Direct3D.Device = Nothing
Private Function Init3d() As Boolean
Try
Dim pparams As New PresentParameters
pparams.Windowed = True
pparams.SwapEffect = SwapEffect.Discard
dev = New Microsoft.DirectX.Direct3D.Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, pparams)
Return True
Catch ex As DirectXException
Return False
End Try
End Function
Private Sub render()
dev.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)
dev.BeginScene()
dev.EndScene()
dev.Present()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Me.render()
End Sub
Sub main()
If Init3d() = False Then MsgBox("Couldn't init.")
End Sub
End Class
Imports Microsoft.DirectX.Direct3D
Public Class Form1
Private dev As Microsoft.DirectX.Direct3D.Device = Nothing
Private Function Init3d() As Boolean
Try
Dim pparams As New PresentParameters
pparams.Windowed = True
pparams.SwapEffect = SwapEffect.Discard
dev = New Microsoft.DirectX.Direct3D.Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, pparams)
Return True
Catch ex As DirectXException
Return False
End Try
End Function
Private Sub render()
dev.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)
dev.BeginScene()
dev.EndScene()
dev.Present()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Me.render()
End Sub
Sub main()
If Init3d() = False Then MsgBox("Couldn't init.")
End Sub
End Class
and this tutorial when I debug/run I get this error:
dev.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)
NullReferenceException was unhandled. Object Reference not set to an instance of an object.
All help is greatly appreciated

Direct3D Initialization
Lauriemoore
But still not running, also I downloaded SDK, these samples still not running!!! It fails while creating device... although compiled samples from microsoft SDK are running well... why codes from same SDK won't run
abc_acb
As the error says - dev is 'nothing'.
The problem could be a couple of things.
1. Your render code is getting called before the device is set up becuase of the way you have things ordered. Wrapp the code in Paint with
if Not dev is Nothing
then render will not be called until the device is properly set up
2. Put some breakpoints in your Main routine and make sure its getting called at all.
Cool_DBA
still it cannot create device, I tried to change some parameters, nothing matters.
[code]
Imports microsoft.DirectX
Imports Microsoft.DirectX.Direct3D
Public Class Form1
Private dev As Microsoft.DirectX.Direct3D.Device = Nothing
Private Function Init3d() As Boolean
Try
Dim pparams As New PresentParameters
pparams.Windowed = True
pparams.SwapEffect = SwapEffect.Discard
dev = New Microsoft.DirectX.Direct3D.Device(0, DeviceType.Hardware, Me, CreateFlags.SoftwareVertexProcessing, pparams)
Return True
Catch ex As DirectXException
Return False
End Try
End Function
Private Sub render()
dev.Clear(ClearFlags.Target, Color.Blue, 1.0F, 0)
dev.BeginScene()
dev.EndScene()
dev.Present()
End Sub
Sub main()
If Init3d() = False Then
MsgBox("Couldn't init.")
else
Me.render()
End If
End Sub
Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Call main()
End Sub
End Class
[/code]
David Parslow