|
-
July 12th, 2001, 06:44 AM
#1
Casting
Hi,
I guess this is rather simple but I don't know how to do it.
I'm calling a method that returns a reference, and I want to cast that
reference so I can use the member variables.
In c++ I would do like this.
Datatype* myDatatype;
myDataType = (Datatype*) GetReference(...)
myDataType->memberData....
Is this possible in VB?
-
July 12th, 2001, 07:28 AM
#2
Re: Casting
in C, you can do casting because you got pointer. and casting is nothing more than put the pointer into a new location and assume that the data in there is of certain type. whenever you access the member variable of it, compiler will just calculate the location (offset) of the member variable from the pointer. in C++, this concept added to object.
For VB, I doubt you can do casting as easy as C++ because VB don't have pointer. below code show how you can cast a type from a byte array.
private Declare Sub RtlMoveMemory Lib "kernel32" (Des as Any, Src as Any, byval Length as Long)
private Type test
test1 as Long
test2 as Long
End Type
private Function ReturnTest() as Byte()
Dim a(7) as Byte
a(0) = 1
a(4) = 2
ReturnTest = a
End Function
private Sub Form_Load()
Dim i as test
Dim l() as Byte
l = ReturnTest
RtlMoveMemory i, l(0), len(i)
Debug.print i.test1
Debug.print i.test2
End Sub
HTH
cksiow
http://vblib.virtualave.net - share our codes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|