VB.Net + DX is really not the best team. The "problem" is the managed code.Quote:> Is it possible to use direct3d 8 with VB.net, as I get an
> error everytime I call the function
> direct3ddevice8.drawprimitiveup. I was wondering if there
> is anyway to stop this error. The error is that when
> trying to pass the first member of the vertex array, it
> can't be converted to type system.intptr. I hope you can
> help figure this out.
So getting real pointers is not a part of VB.Net at all and only limited in
C#. You can not get a pointer because it's said that the garbage collector
can rearrange memory and you can never be sure that a pointer is still valid
after passing it to DX. At the moment, in VB.Net you have three choices:
- Write a VB6 DLL and use it by your VB.Net app
- write unsafe code in C#
- Use the marshal class
In your case you probably mean the argument VertexStreamZeroDataArray. It's
declared "As Any" and that's converted to System.Intptr when importing the
Using the Marshal class (System.Runtime.InteropServices.Marshal):
Have a look at it's functions: They are there to copy managed data to
previously reserved memory. This memory can be accessed by a "normal" Intptr
and therefore passed to DX. Simple Example:
dim Ptr as Intptr
dim Vertex as d3dvertex
Ptr = Marshal.AllocHGlobal(len(Vertex))
Marshal.StructureToPtr (Vertex, Ptr, True)
Now you can pass the Ptr to DirectX.
That's only an example (not sure if using the len function returns the
correct result for reserving memory) of what the Marshal class is for. Big
disadvantage: Copying everything is not an option for applications where
performance is a main issue, at all. So I'd prefer writing a C# library and
use unsafe code.
I'm rather new to this subject so I'm not sure if *everything* can be
achieved by working around, using C# or VB6-DLLs.