How to get a pointer to a byte array in vb4 or vb5 
Author Message
 How to get a pointer to a byte array in vb4 or vb5

Hi

I need to pass a pointer to a byte array (unicode) to an api function.
My question is now, how I can get this pointer (address) into a vb long
variable?

Any help appreciated
Stephan Brunner



Tue, 09 Nov 1999 03:00:00 GMT  
 How to get a pointer to a byte array in vb4 or vb5

This is a multi-part message in MIME format.

------=_NextPart_000_01BC6769.EBFD3C00
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Use the VarPtr() function. It's not documented, but it's there. Don't =
know if it's in VB4, but VB5's got it. Assuming you pass the length of =
the byte array as well, you just call it like this:
myPtr =3D VarPtr(ByteArray(0))
... or whatever the lower bound of the array is.
--
-- Ben
SiteBuilder Network Level 2
Ben's VB5 Page -- This site has been Activated!
http://www.{*filter*}highway.com/~psy/
Requires IE3.01 or higher...

 Stephan Brunner wrote in article =

I need to pass a pointer to a byte array (unicode) to an api function.
My question is now, how I can get this pointer (address) into a vb long
variable?

------=_NextPart_000_01BC6769.EBFD3C00
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML 3.2//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"Trident 4.71.0544.0"' name=3DGENERATOR>

</HEAD>
<BODY>
<P><FONT face=3DArial size=3D2>Use the VarPtr() function. It's not =
documented, but=20
it's there. Don't know if it's in VB4, but VB5's got it. Assuming you =
pass the=20
length of the byte array as well, you just call it like this:</FONT>

<P><FONT face=3DArial size=3D2>myPtr =3D VarPtr(ByteArray(0))</FONT>

<P><FONT face=3DArial size=3D2>... or whatever the lower bound of the =
array is.<BR>
--<BR>
<HTML><BODY><FONT size=3D2>-- Ben<BR>
SiteBuilder Network Level 2<BR>
Ben's VB5 Page -- This site has been Activated!<BR>
<A=20
href=3D"http://www.{*filter*}highway.com/~psy/">http://www.{*filter*}highway.com/~p=
sy/</A><BR>
Requires IE3.01 or higher...<BR>
</FONT></FONT>

<P><FONT face=3DArial size=3D2> <EM><FONT color=3D#808080>Stephan=20


<HTML><BODY>I need to pass a pointer to a byte array (unicode) to an api =

function.<BR>
My question is now, how I can get this pointer (address) into a vb =
long<BR>
variable?<BR>
</FONT></EM><FONT size=3D2><BR>
</FONT></FONT></P>

</BODY></HTML>

------=_NextPart_000_01BC6769.EBFD3C00--



Tue, 09 Nov 1999 03:00:00 GMT  
 How to get a pointer to a byte array in vb4 or vb5

Depending on how the call is declared you may need only pass the parameter
as bytearray(0).
VarPtr -- as well as StrPtr and ObjPtr -- are available in VB4, but you
must declare them out of vb4 runtime DLL.  If I can find the calls again
I'll post them.
--
-Chris




Use the VarPtr() function. It's not documented, but it's there. Don't know
if it's in VB4, but VB5's got it. Assuming you pass the length of the byte
array as well, you just call it like this:
myPtr = VarPtr(ByteArray(0))
... or whatever the lower bound of the array is.
--
-- Ben
SiteBuilder Network Level 2
Ben's VB5 Page -- This site has been Activated!
http://www.{*filter*}highway.com/~psy/
Requires IE3.01 or higher...


I need to pass a pointer to a byte array (unicode) to an api function.
My question is now, how I can get this pointer (address) into a vb long
variable?

----------



Tue, 09 Nov 1999 03:00:00 GMT  
 How to get a pointer to a byte array in vb4 or vb5



Quote:
> Hi

> I need to pass a pointer to a byte array (unicode) to an api function.
> My question is now, how I can get this pointer (address) into a vb long
> variable?

Hi Stephan!

Ben points right, the VB4-Declare is:
Declare Function VarPtr Lib "vb40032" (V As Any) As Long

If you want to pass a VB-Unicode-String, do'nt do something like that:
pStrg = VarPtr(ByVal Strg)
pStrg will be a valid Pointer to a BSTR, but VB has than already made a
Unicode-to-Ansi-Conversion.

You probably use it this way, but something like this will sure work:
Dim ByteArr() As Byte
ByteArr = Strg
pStrg = VarPtr(ByteArr(0))

In VB5 there is a Function StrPtr but I have'nt tested it yet.

Olaf!



Tue, 09 Nov 1999 03:00:00 GMT  
 How to get a pointer to a byte array in vb4 or vb5

Maybe I don't understand the question but, if you are passing the
pointer to the array as a parameter then why not pass it ByRef which
will automatically pass the pointer to the array for you.  This seems
like the most obvious solution unless I am completely overlooking
something (Which is not unlikely).

Irwin

Quote:



> > Hi

> > I need to pass a pointer to a byte array (unicode) to an api function.
> > My question is now, how I can get this pointer (address) into a vb long
> > variable?

> Hi Stephan!

> Ben points right, the VB4-Declare is:
> Declare Function VarPtr Lib "vb40032" (V As Any) As Long

> If you want to pass a VB-Unicode-String, do'nt do something like that:
> pStrg = VarPtr(ByVal Strg)
> pStrg will be a valid Pointer to a BSTR, but VB has than already made a
> Unicode-to-Ansi-Conversion.

> You probably use it this way, but something like this will sure work:
> Dim ByteArr() As Byte
> ByteArr = Strg
> pStrg = VarPtr(ByteArr(0))

> In VB5 there is a Function StrPtr but I have'nt tested it yet.

> Olaf!



Tue, 09 Nov 1999 03:00:00 GMT  
 How to get a pointer to a byte array in vb4 or vb5



Quote:
> Maybe I don't understand the question but, if you are passing the
> pointer to the array as a parameter then why not pass it ByRef which
> will automatically pass the pointer to the array for you.  

Hi Irwin!

Thats right, but in some cases you really need the VarPtr-Function.
Stephan was not writing that he pass the Byte-Array directly.
If it is part of an ByRef passed User-Defined-Type than he must use the
VarPtr()-Function to fill a Long-Member wich points to a
Unicode-Byte-Array.

Type TypeWithUnicodeByteArr
   pByteArr as Long
   ...
End Type

This Type-Declare does'nt work:
Type TypeWithUnicodeStrg
   UniStrg as String      'takes 4 Bytes
   ...
End Type
UniStrg is here a Pointer to an BSTR, but after passing a UDT to a
DLL-Function all contained Unicode-Strings are converted to ANSI.

Another Type:
Type TypeWithUnicodeByteArrDirect
   ByteArr() as Byte     'takes 4 Bytes
   ...
End Type
Here's the first Member also a Pointer, but it points not directly to the
Arrays first Position. It points to another struct (the Pointer to the
start of the Byte-Array is located at Byte-Position 13-16)

Olaf!



Wed, 10 Nov 1999 03:00:00 GMT  
 How to get a pointer to a byte array in vb4 or vb5

Schidt,
Thanks for clearing that up.

Irwin.

But what would you do with a brain if you had one?
                        Dorthy - "Wizzard of Ozz"



Mon, 15 Nov 1999 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. How to get a pointer to a byte array in vb4 or vb5

2. How to get a pointer to a byte array in vb4 or vb5

3. Passing in a pointer to an array of bytes

4. how to get the pointer to a byte array

5. Passing a byte pointer to a DLL from VB4.0

6. Need to convert a 16 byte array of bytes to 4 byte integer

7. Getting a string out of a C byte array

8. Getting an array of Byte from a picture

9. Fun with APIs- Getting an array of records with pointers to strings

10. Declaring an array of pointers in Visual Basic (and putting and getting data from it)

11. Declaring an array of pointers in Visual Basic (and putting and getting data from it)

12. Getting an array of records with pointers to strings from an API

 

 
Powered by phpBB® Forum Software