Using the Direct3DDevice in a PureBasic DLL

Blitz3D Forums/Blitz3D Userlibs/Using the Direct3DDevice in a PureBasic DLL

ChristianK(Posted 2007) [#1]
I tried to access the Direct3DDevice returned by SystemProperty to draw some graphics on the screen, just for fun :)

Here's the PureBasic code. It doesn't work. I get a 'Memory Access Violation' when I call the 'Render' function. The error occurs in the line where the DrawPrimitive function is called. I also tried other functions of IDirect3DDevice, but no one works.
I'm just a beginner in PureBasic, so I hope you can help me.

Structure vertex
  x.f
  y.f
  z.f
EndStructure

*device.IDirect3DDevice7

ProcedureDLL SetDevice( *dev.IDirect3DDevice7 )
  device = dev
  
  If Not device
    ProcedureReturn( 0 )
  EndIf

  ProcedureReturn( 1 )
EndProcedure

ProcedureDLL Render( )
  Shared *device
  
  Dim verts.vertex( 3 )
  
  verts( 0 )\x = -1
  verts( 0 )\y = 1
  verts( 0 )\z = 0
  
  verts( 1 )\x = 1
  verts( 1 )\y = 1
  verts( 1 )\z = 0
  
  verts( 2 )\x = 1
  verts( 2 )\y = -1
  verts( 2 )\z = 0
  
  verts( 3 )\x = -1
  verts( 3 )\y = -1
  verts( 3 )\z = 0
  
  *device\DrawPrimitive( 6, $002, verts, 4, 0 )
  
  ProcedureReturn( 0 )
EndProcedure



Tom(Posted 2007) [#2]
I dunno anything about PB, but does PB use a different convention on arrays, i.e, Dim verts.vertex(3) < does that have 4 elements (0,1,2,3)?

Otherwise, the params passed to drawprimitive looks fine.


ChristianK(Posted 2007) [#3]
Yes, arrays are BlitzBasic style.

I think there is a problem with the device passed to 'SetDevice'. Maybe it is not 'compatible' with the Blitz3D integer handles.