VB.NET and DirectX Surfaces

Couldn't find a better place to post this, so I suppose here will do.

I'm trying to create an application using VB.NET and DirectX 9 (Microsoft.DirectX). I'm having a problem with the surfaces (Microsoft.DirectX.DirectDraw.Surface).

After I create one surface, DirectDraw raises an error when I attempt to create another. For example:

Dim descAsNew SurfaceDescription

Dim capsAsNew SurfaceCaps

m_DirectDraw.SetCooperativeLevel(m_MainForm, CooperativeLevelFlags.FullscreenExclusive)

m_DirectDraw.SetDisplayMode(m_DisplayWidth, m_DisplayHeight, m_DisplayDepth, 0,False)

desc.SurfaceCaps.PrimarySurface =True

desc.SurfaceCaps.Flip =True

desc.SurfaceCaps.Complex =True

desc.BackBufferCount = 1

m_PrimarySurface =New Surface(desc, m_DirectDraw)

caps.BackBuffer =True

m_BackBuffer = m_PrimarySurface.GetAttachedSurface(caps)

m_BackBuffer.ForeColor = Color.White

m_BackBuffer.FillStyle = 0

desc.Clear()

Dim surfaceAsNew Surface(desc, m_DirectDraw)

There are two lines highlighted in the above code. Both of them are exactly the same, aside from the fact that the object names are different. The first object (m_PrimarySurface) is created without a problem and functions properly. However, the 2nd object (surface), will not be created. The following error is raised:

Value does not fall within the expected range.

To make things even more odd, if I place the 2nd object's (surface) line of code before the first one, so that surface is created before m_PrimarySurface, then surface is successfully created, and m_PrimarySurface raises the same error as above.

Any thoughts?

[2755 byte] By [Clodaus] at [2008-2-5]
# 1
okay, I managed to resolve the first issue, now I'm back to a previous one - it won't allow me to load a surface from a file without giving me the value does not fall within the expected range error.
Clodaus at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2
alright it's only loading .bmp files :P I can live with it. What a large selection of meaninless posts ^_^
Clodaus at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic Language...