Hmmm, without knowing exactly what a 'vector3' is, or what someMatrix is, it's not really convertable to anything meaningful. It'd probably translate to:
Dim myVector3 as Vector3
with Vector3 as some kind of structure. You could then get the pointer to the structure through marshalling - it all depends exactly what you are doing. It is possible that you don't need to use pointers at all.
If Vector3 is a struct and M31 is a float, then both are value types and you need "real" pointers (using * and &), which you can only do in C# and C++. VB does not support this. Your best bet is to write these parts in C# and then reference the C# assembly from the rest of your VB class library.
You must be working in an unsafe method or code block in C#. VB does not support unsafe code. If you're willing to deal with a managed reference, you can do the following in C#:
Vector3 myVector3 = someMatrix.M31;
Then in VB:
Dim myVector3 As Vector 3 = someMatrix.M31
As I said, you can't work with raw pointers in VB as you can in C#. Even in C#, you should be pinning your data structure before playing with pointers to prevent the GC from moving the object while you're using it.
Vector3 is as structure, and someMatrix.M31 is a floating point member of the Matrix structure so you can't convert a structure to a float
would
Dim myVector3 as Vector3 = CType(CObj(someMatrix.M31), Vector3)
work
i know, build and try, but i am creating a very large library that cannot be used until all parts are in place so i just wondered if you knew for sure.
Responding to your last comment in the other and now locked thread:
Your case would compile however would fail at runtime because even if you cast someMatrix.M31 into an object, it still retains the properties of it’s higher type as well that is not able to be cast into the type of Vector3.
Another issue you would run into is that you would run into is that with Vector3 being a structure, anytime you do an assignment such as
Dim myVector3 As Vector3 = someMatrix
You end up with myVector3 having a separate (but initially identical) copy of someMatrix.
If Vector3 were a class, then such an assignment would result in two separate variables referencing the same object in memory... however that is still not a pointer.
With managed code these days...there are very few reasons to utilize pointers upfront in code with C# and...(the behind the scenes CLR and JIT take care of that need) especially in VB(VB doesn't use pointers). I have found that just about all C/C# code can be converted to VB and I'll step that up to ALL managed C# code can be converted!
It should be possible - on the link provided to the other thread, ignore the flaming and find the code that uses marshalas - that should give you a few pointers on how to do it.
Basically, what the code you have seems to be doing is using the fact that the internal representation of the matrix object is a sequence of floats (same as the vector data representation) to obtain a reference to a particular row(or column ) of the matrix into a vector3 (these seem to be the direct3d objects ).
Note that this is risky programming - if in the future they modify the order or type of elements on the matrix, you have an Instant bug, no water required ;)
Note also that it's probably an optimization to allow him to modify the matrix without going through the exposed members, which probably means that if you do use marshalas you might be doing yourself a disservice, since performance is likely to go down the drain compared to doing any edits you do to the vector3 directly in the matrix also.
Pointers : Converting to VB
InvertedAerials
what about code marked as unsafe in c# (ALL managed C# can be converted)
Thanks
Suketu
Hmmm, without knowing exactly what a 'vector3' is, or what someMatrix is, it's not really convertable to anything meaningful. It'd probably translate to:
Dim myVector3 as Vector3
with Vector3 as some kind of structure. You could then get the pointer to the structure through marshalling - it all depends exactly what you are doing. It is possible that you don't need to use pointers at all.
mehmet bey
Eddie Deyo
Jeff,
Although you may have some wading to do, pointers in VB were discussed in this thread.
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=223058&SiteID=1
bill perlman
RonDesta
THHNO
Vector3 is as structure, and someMatrix.M31 is a floating point member of the Matrix structure so you can't convert a structure to a float
would
Dim myVector3 as Vector3 = CType(CObj(someMatrix.M31), Vector3)
work
i know, build and try, but i am creating a very large library that cannot be used until all parts are in place so i just wondered if you knew for sure.
Thanks Again
Chandra B
CHTHONIC
G'day,
I don't know if this will help you or not, but take a look at this link:
http://msdn.microsoft.com/msdnmag/issues/06/02/PasteAs/
GianniAb
Responding to your last comment in the other and now locked thread:
Your case would compile however would fail at runtime because even if you cast someMatrix.M31 into an object, it still retains the properties of it’s higher type as well that is not able to be cast into the type of Vector3.
Another issue you would run into is that you would run into is that with Vector3 being a structure, anytime you do an assignment such as
Dim myVector3 As Vector3 = someMatrix
You end up with myVector3 having a separate (but initially identical) copy of someMatrix.
If Vector3 were a class, then such an assignment would result in two separate variables referencing the same object in memory... however that is still not a pointer.
Discoman
chaser7016
It should be possible - on the link provided to the other thread, ignore the flaming and find the code that uses marshalas - that should give you a few pointers on how to do it.
Basically, what the code you have seems to be doing is using the fact that the internal representation of the matrix object is a sequence of floats (same as the vector data representation) to obtain a reference to a particular row(or column ) of the matrix into a vector3 (these seem to be the direct3d objects ).
Note that this is risky programming - if in the future they modify the order or type of elements on the matrix, you have an Instant bug, no water required ;)
Note also that it's probably an optimization to allow him to modify the matrix without going through the exposed members, which probably means that if you do use marshalas you might be doing yourself a disservice, since performance is likely to go down the drain compared to doing any edits you do to the vector3 directly in the matrix also.
kenc2005
To avoid the wading through a, rather mild, flame war; look at:
Marshal.StructureToPtr and Marshal.PtrToStructure
And an particular the other Marshal members in the System.Runtime.InteropServices.