Converting 4 bytes into Long  
Author Message
rmilbrand





PostPosted: Wed Dec 28 02:28:07 CST 2005 Top

Visual Basic >> Converting 4 bytes into Long

Hello,
I use CopyMemory() to convert 4 bytes into long like that:
Dim lMediaID As Long
CopyMemory lMediaID, b.bBytes(0), 4

lMediaID is a retrieved object handle used in another API.
However that another API complains about invalid handle, which puts in doubt
the above conversion.
What can be wrong in that scenario?
Frank

Visual Studio104  
 
 
Mike





PostPosted: Wed Dec 28 02:28:07 CST 2005 Top

Visual Basic >> Converting 4 bytes into Long


> I use CopyMemory() to convert 4 bytes into long like that:
> Dim lMediaID As Long
> CopyMemory lMediaID, b.bBytes(0), 4
> lMediaID is a retrieved object handle used in another API.
> However that another API complains about invalid handle

Hang on a sec. You've got me confused? You're saying that lMediaID is a
*retreived* object handle, whereas in your code above it is simply a Long
into which you are dumping some data from the byte array. Presumably your
bBytes() is a Byte array in a UDT called b? If so, then where are you
getting the data to initially fill the byte array? If for some reason you
are initially filling the byte array with the four bytes of data that
represent a handle to something then have you checked that you are you
filling them in the correct order (lowest order byte in element zero up to
highest order byte in element three)? Also, is the original handle obtained
in the same VB app?

Mike



 
 
Michael





PostPosted: Wed Dec 28 09:45:26 CST 2005 Top

Visual Basic >> Converting 4 bytes into Long

> Hello,
> I use CopyMemory() to convert 4 bytes into long like that:
> Dim lMediaID As Long
> CopyMemory lMediaID, b.bBytes(0), 4
>
> lMediaID is a retrieved object handle used in another API.
> However that another API complains about invalid handle, which puts in
> doubt
> the above conversion.
> What can be wrong in that scenario?

In addition to what mike said, the above code is correct *if* b.bytes does
contain a valid handle. What I suspect you are doing is calling an api which
retrieves information into b? Then from b you want to get a handle. If my
assumptions are correct then the problem might be how you've defined
b.bBytes. If you've defined it as a fixed length array then it should work
but if you've defined it as variable length then you'd have problems. On the
other hand, if my assumptions are incorrect ignore me and refer back to
mikes post :-)

Michael