VB and sizeof 
Author Message
 VB and sizeof

Is there anything similar to C++'s 'sizeof' function for VB?  It seems you
can't call this API (since it's not really and API) from VB.

I'm trying to find the size of the VB 'FileSystemObject' so that I can move
it using memcopy.  Any suggestions?

Thanks,
Tim



Thu, 13 Jun 2002 03:00:00 GMT  
 VB and sizeof
Timothy,

Quote:
> Is there anything similar to C++'s 'sizeof' function for VB?  It seems you
> can't call this API (since it's not really and API) from VB.

Use Len().

Quote:
> I'm trying to find the size of the VB 'FileSystemObject' so that I can move
> it using memcopy.  Any suggestions?

Um, that's probably not a good idea, unless you *really* know what you're doing.
You do know there's no reference counting when you do that sort of thing, right?
Weak references and so on?

In any case, you need ObjPtr() to retreive a pointer to the object, and then use
MoveMemory (not memcpy -- that doesn't exist in Win32) on that. As most other
pointers, this will be 4 bytes in length, since it is a LONG.

Good luck ;-)

. . . . . . . . . . . . . . . . . . . . . .
Please post/reply to the
newsgroup(s)

Klaus H. Probst, MVP
   http://www.vbbox.com/
   http://www.mvps.org/ccrp/



Fri, 14 Jun 2002 03:00:00 GMT  
 VB and sizeof
LenB() is probably a safer bet if you are doing API calls or Lsets...

Quote:

>Timothy,

>> Is there anything similar to C++'s 'sizeof' function for VB?  It seems
you
>> can't call this API (since it's not really and API) from VB.

>Use Len().

>> I'm trying to find the size of the VB 'FileSystemObject' so that I can
move
>> it using memcopy.  Any suggestions?

>Um, that's probably not a good idea, unless you *really* know what you're
doing.
>You do know there's no reference counting when you do that sort of thing,
right?
>Weak references and so on?

>In any case, you need ObjPtr() to retreive a pointer to the object, and
then use
>MoveMemory (not memcpy -- that doesn't exist in Win32) on that. As most
other
>pointers, this will be 4 bytes in length, since it is a LONG.

>Good luck ;-)

>. . . . . . . . . . . . . . . . . . . . . .
>Please post/reply to the
>newsgroup(s)

>Klaus H. Probst, MVP
>   http://www.vbbox.com/
>   http://www.mvps.org/ccrp/



Fri, 14 Jun 2002 03:00:00 GMT  
 VB and sizeof
Actually I tried both Len and LenB and I get the same error ('object does
not support this property').  I agree that it is a bit scary copying the
values through memory, but I'm not sure how else to do it.  What I need to
do is move the FileSystemObject variable from one machine to another (sort
of like how you would transfer a file).  I know who to move the value of a
long or integer, but I know how many bytes they take up so I can use it in
my memcopy (or equivalent).

Essentially I'm trying to get the FileSystemObject to a remote computer that
is not located on a network.  How can I transfer the value of a variable
from one machine to another (without using ActiveX automation)?

Thanks,
Tim



Fri, 14 Jun 2002 03:00:00 GMT  
 VB and sizeof

I'm not too sure if Scripting.FileSystemObject can cross machine
boundries...

But, I ran a quick test to just pass it around:

Private Sub Command1_Click()

    Dim FS As New FileSystemObject
    Form2.GetDrives FS

End Sub

Public Sub GetDrives(ByRef FS As Scripting.FileSystemObject)

    Dim thing As Variant
    Label1 = ""
    Me.Show

    For Each thing In FS.Drives
        Label1 = Label1 & " " & thing.DriveLetter
    Next

End Sub

This worked fine...  You may need to use an UNC to connect to your remote
drives.

Private Sub Command2_Click()

    Dim FS As New FileSystemObject

    FS.CopyFile "\\remotecomputer\share\file.txt",
"\\localcomputer\path\file.txt"

End Sub

This works fine...  'course, I don't know what you are really trying to
accomplish, but I hope this helps.

-Kris

Quote:

>Actually I tried both Len and LenB and I get the same error ('object does
>not support this property').  I agree that it is a bit scary copying the
>values through memory, but I'm not sure how else to do it.  What I need to
>do is move the FileSystemObject variable from one machine to another (sort
>of like how you would transfer a file).  I know who to move the value of a
>long or integer, but I know how many bytes they take up so I can use it in
>my memcopy (or equivalent).

>Essentially I'm trying to get the FileSystemObject to a remote computer
that
>is not located on a network.  How can I transfer the value of a variable
>from one machine to another (without using ActiveX automation)?

>Thanks,
>Tim




Sat, 15 Jun 2002 03:00:00 GMT  
 VB and sizeof
Hi

You better not try to copy a COM object. What you get in VB when you
instantiate an object is a pointer to an interface, in this case a pointer
to interface IFileSystem. You can't know how the properties are implemented.
They could be private variables or calculated values, the object could
infact support other interfaces (like in this case IDispatch). So you can't
know how to copy the 'state' of the object using a memory copy.
The only thing you can do is copy the memory pointer to the interface into
another variable, but this is something you really don't want to do in this
case.

Hope this helps.

bye




Sun, 16 Jun 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Q: "Sizeof" in VB

2. Sizeof in vb?

3. sizeof for VB objects?

4. Sizeof in VB

5. Sizeof in VB

6. 'sizeof' in VB

7. C "sizeof" in VB

8. Sizeof objects

9. VB6 SizeOf Method

10. SizeOf as in C

11. SizeOf Directory

12. sizeof

 

 
Powered by phpBB® Forum Software