reading bytes from a long

reading bytes from a long

Post by KWilliam » Wed, 10 May 2000 04:00:00



Hello all.... hope you can help:

I'm using an external 3rd party dll (no VB documentation, only C). I'm being
returned a LONG . Can someone tell me how to examine each byte making up the
long?

I can get the address of the variable, (presumably the first byte) with the
varptr function, but I'm unsure of how to do pointer arithmetic in VB. Can
some kind soul help?
TIA
KWilliams

 
 
 

reading bytes from a long

Post by James Pars » Wed, 10 May 2000 04:00:00


Look up the LSET statement. What you do is create two
UDT's, one consisting of a LONG, and the other
consisting of a 4 byte array.  Put your LONG into
the 1st UDT and use LSET to set the 2nd UDT
equal to the first.  The LONG gets moved into the
byte array.

On Tue, 9 May 2000 17:16:10 +0100, "KWilliams"


>Hello all.... hope you can help:

>I'm using an external 3rd party dll (no VB documentation, only C). I'm being
>returned a LONG . Can someone tell me how to examine each byte making up the
>long?

>I can get the address of the variable, (presumably the first byte) with the
>varptr function, but I'm unsure of how to do pointer arithmetic in VB. Can
>some kind soul help?
>TIA
>KWilliams


 
 
 

reading bytes from a long

Post by Florian Ege » Wed, 10 May 2000 04:00:00


this is a very simple solution:

        if the original declaration is
Declare Function MyFunction Lib "Name.dll" () as Long

        then write:

Type LngBytes
    A as Byte
    B as Byte
    C as Byte
    D as Byte
End Type
Declare Function MyFunction Lib "Name.dll" () as LngBytes

        to call the function:
Private Sub Command1_Click()
    Dim RetVal As LngBytes
    RetVal = MyFunction
    Text1 = RetVal.A
    Text2 = RetVal.B
    Text3 = RetVal.C
    Text4 = RetVal.D
End Sub

hope this helps

Florian Egel
FLOMIX Studios '97
http://www.Flomix.de



Quote:> Hello all.... hope you can help:

> I'm using an external 3rd party dll (no VB documentation, only C). I'm
being
> returned a LONG . Can someone tell me how to examine each byte making up
the
> long?

> I can get the address of the variable, (presumably the first byte) with
the
> varptr function, but I'm unsure of how to do pointer arithmetic in VB. Can
> some kind soul help?
> TIA
> KWilliams

 
 
 

reading bytes from a long

Post by Florian Ege » Wed, 10 May 2000 04:00:00


this is a very simple solution:

        if the original declaration is
Declare Function MyFunction Lib "Name.dll" () as Long

        then write:

Type LngBytes
    A as Byte
    B as Byte
    C as Byte
    D as Byte
End Type
Declare Function MyFunction Lib "Name.dll" () as LngBytes

        to call the function:
Private Sub Command1_Click()
    Dim RetVal As LngBytes
    RetVal = MyFunction
    Text1 = RetVal.A
    Text2 = RetVal.B
    Text3 = RetVal.C
    Text4 = RetVal.D
End Sub

hope this helps

Florian Egel
FLOMIX Studios '97
http://www.Flomix.de



Quote:> Hello all.... hope you can help:

> I'm using an external 3rd party dll (no VB documentation, only C). I'm
being
> returned a LONG . Can someone tell me how to examine each byte making up
the
> long?

> I can get the address of the variable, (presumably the first byte) with
the
> varptr function, but I'm unsure of how to do pointer arithmetic in VB. Can
> some kind soul help?
> TIA
> KWilliams

 
 
 

reading bytes from a long

Post by KWilliam » Thu, 11 May 2000 04:00:00


Thankyou both very much. It's very much appreciated!
KWilliams
 
 
 

reading bytes from a long

Post by J Fren » Thu, 11 May 2000 04:00:00


Just to prevent anyone getting confused by HHS's  posting :

On Wed, 10 May 2000 07:10:52 GMT, "Howard Henry Schlunder"


>Seeing as how you are getting the address of a Long using VarPtr, you cannot
>just happen to have the data in a UDT and then use LSet to place it in

If you can use VarPtr then you HAVE got the variable

Quote:>another UDT.  Instead, you *must* (there are no alternatives) use the

Yes you can and that IS THE alternative

Quote:>CopyMemory API function.  Something like this demonstraights its use and is
>modeled after your potential use of VarPtr:

Funny isn't it, how people want to use APIs when it is actually
simpler to do something in pure VB

Private Type TLong
   Value As Long
End Type

Private Type TBytes
   Value(1 To 4) As Byte
End Type

Private Sub Command1_Click()

    Dim L As TLong
    Dim B As TBytes
    L.Value = -1
    LSet B = L
    For L9 = 1 To 4
        Debug.Print B.Value(L9)
    Next

End Sub        

>Option Explicit
>Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
>    (Destination As Any, Source As Any, ByVal Length As Long)

>Private Sub Command1_Click()
>Dim MyLongVar As Long, PositionOfMyLongVar As Long
>Dim DestinationBytes(3) As Byte

>  MyLongVar = 666000666
>  PositionOfMyLongVar = VarPtr(MyLongVar)
>  Call CopyMemory(DestinationBytes(0), ByVal PositionOfMyLongVar, 4)

>  Debug.Print "Bytes: " & DestinationBytes(0), DestinationBytes(1), _
>    DestinationBytes(2), DestinationBytes(3)
>End Sub

>Howard Henry Schlunder



>> Hello all.... hope you can help:

>> I'm using an external 3rd party dll (no VB documentation, only C). I'm
>being
>> returned a LONG . Can someone tell me how to examine each byte making up
>the
>> long?

>> I can get the address of the variable, (presumably the first byte) with
>the
>> varptr function, but I'm unsure of how to do pointer arithmetic in VB. Can
>> some kind soul help?
>> TIA
>> KWilliams

 
 
 

reading bytes from a long

Post by Howard Henry Schlunde » Thu, 11 May 2000 04:00:00


Hey, I canceled my message less than five minutes after I posted it.  I went
through and reread the question and realized I completely neglected the
first paragraph.  It was my mistake and you quoting everything I attempted
to cancel isn't helping...

Howard Henry Schlunder


> Just to prevent anyone getting confused by HHS's  posting :

> On Wed, 10 May 2000 07:10:52 GMT, "Howard Henry Schlunder"

> >Seeing as how you are getting the address of a Long using VarPtr, you
cannot
> >just happen to have the data in a UDT and then use LSet to place it in

> If you can use VarPtr then you HAVE got the variable

> >another UDT.  Instead, you *must* (there are no alternatives) use the

> Yes you can and that IS THE alternative

> >CopyMemory API function.  Something like this demonstraights its use and
is
> >modeled after your potential use of VarPtr:

> Funny isn't it, how people want to use APIs when it is actually
> simpler to do something in pure VB

> Private Type TLong
>    Value As Long
> End Type

> Private Type TBytes
>    Value(1 To 4) As Byte
> End Type

> Private Sub Command1_Click()

>     Dim L As TLong
>     Dim B As TBytes
>     L.Value = -1
>     LSet B = L
>     For L9 = 1 To 4
>         Debug.Print B.Value(L9)
>     Next

> End Sub

> >Option Explicit
> >Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
> >    (Destination As Any, Source As Any, ByVal Length As Long)

> >Private Sub Command1_Click()
> >Dim MyLongVar As Long, PositionOfMyLongVar As Long
> >Dim DestinationBytes(3) As Byte

> >  MyLongVar = 666000666
> >  PositionOfMyLongVar = VarPtr(MyLongVar)
> >  Call CopyMemory(DestinationBytes(0), ByVal PositionOfMyLongVar, 4)

> >  Debug.Print "Bytes: " & DestinationBytes(0), DestinationBytes(1), _
> >    DestinationBytes(2), DestinationBytes(3)
> >End Sub

> >Howard Henry Schlunder



> >> Hello all.... hope you can help:

> >> I'm using an external 3rd party dll (no VB documentation, only C). I'm
> >being
> >> returned a LONG . Can someone tell me how to examine each byte making
up
> >the
> >> long?

> >> I can get the address of the variable, (presumably the first byte) with
> >the
> >> varptr function, but I'm unsure of how to do pointer arithmetic in VB.
Can
> >> some kind soul help?
> >> TIA
> >> KWilliams

 
 
 

reading bytes from a long

Post by J Fren » Thu, 11 May 2000 04:00:00


Sorry Henry

No way I could know that you had cancelled it.

I got the message and thought you were a w____r - I saw a later
posting - Textboxes etc and realized that you were not

Good Luck - Jerry

On Wed, 10 May 2000 16:15:49 GMT, "Howard Henry Schlunder"


>Hey, I canceled my message less than five minutes after I posted it.  I went
>through and reread the question and realized I completely neglected the
>first paragraph.  It was my mistake and you quoting everything I attempted
>to cancel isn't helping...

>Howard Henry Schlunder



>> Just to prevent anyone getting confused by HHS's  posting :

>> On Wed, 10 May 2000 07:10:52 GMT, "Howard Henry Schlunder"

>> >Seeing as how you are getting the address of a Long using VarPtr, you
>cannot
>> >just happen to have the data in a UDT and then use LSet to place it in

>> If you can use VarPtr then you HAVE got the variable

>> >another UDT.  Instead, you *must* (there are no alternatives) use the

>> Yes you can and that IS THE alternative

>> >CopyMemory API function.  Something like this demonstraights its use and
>is
>> >modeled after your potential use of VarPtr:

>> Funny isn't it, how people want to use APIs when it is actually
>> simpler to do something in pure VB

>> Private Type TLong
>>    Value As Long
>> End Type

>> Private Type TBytes
>>    Value(1 To 4) As Byte
>> End Type

>> Private Sub Command1_Click()

>>     Dim L As TLong
>>     Dim B As TBytes
>>     L.Value = -1
>>     LSet B = L
>>     For L9 = 1 To 4
>>         Debug.Print B.Value(L9)
>>     Next

>> End Sub

>> >Option Explicit
>> >Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
>> >    (Destination As Any, Source As Any, ByVal Length As Long)

>> >Private Sub Command1_Click()
>> >Dim MyLongVar As Long, PositionOfMyLongVar As Long
>> >Dim DestinationBytes(3) As Byte

>> >  MyLongVar = 666000666
>> >  PositionOfMyLongVar = VarPtr(MyLongVar)
>> >  Call CopyMemory(DestinationBytes(0), ByVal PositionOfMyLongVar, 4)

>> >  Debug.Print "Bytes: " & DestinationBytes(0), DestinationBytes(1), _
>> >    DestinationBytes(2), DestinationBytes(3)
>> >End Sub

>> >Howard Henry Schlunder



>> >> Hello all.... hope you can help:

>> >> I'm using an external 3rd party dll (no VB documentation, only C). I'm
>> >being
>> >> returned a LONG . Can someone tell me how to examine each byte making
>up
>> >the
>> >> long?

>> >> I can get the address of the variable, (presumably the first byte) with
>> >the
>> >> varptr function, but I'm unsure of how to do pointer arithmetic in VB.
>Can
>> >> some kind soul help?
>> >> TIA
>> >> KWilliams

 
 
 

reading bytes from a long

Post by Howard Henry Schlunde » Fri, 12 May 2000 04:00:00



Quote:> Sorry Henry

> No way I could know that you had cancelled it.

I know; it wasn't your fault.  Your newserver could just be a little more
responsive (either that, I should start spending more time on each message
and realizing in full what I'm posting before I post away.

Quote:> I got the message and thought you were a w____r - I saw a later
> posting - Textboxes etc and realized that you were not

Hehe, you saw that... man, I've got to stop posting dumb things.

> Good Luck - Jerry

> On Wed, 10 May 2000 16:15:49 GMT, "Howard Henry Schlunder"

> >Hey, I canceled my message less than five minutes after I posted it.  I
went
> >through and reread the question and realized I completely neglected the
> >first paragraph.  It was my mistake and you quoting everything I
attempted
> >to cancel isn't helping...

> >Howard Henry Schlunder

 
 
 

reading bytes from a long

Post by J Fren » Fri, 12 May 2000 04:00:00


It's Ok - I've screwed up a few times - anyway the API was useful info
- regardless of context !

Regards - Jerry

On Thu, 11 May 2000 02:17:20 GMT, "Howard Henry Schlunder"




>> Sorry Henry

>> No way I could know that you had cancelled it.

>I know; it wasn't your fault.  Your newserver could just be a little more
>responsive (either that, I should start spending more time on each message
>and realizing in full what I'm posting before I post away.

>> I got the message and thought you were a w____r - I saw a later
>> posting - Textboxes etc and realized that you were not

>Hehe, you saw that... man, I've got to stop posting dumb things.

>> Good Luck - Jerry

 
 
 

1. Byte by byte read into variables...HOW?

|Each field is a fixed length, but not necessarily all used up, so it might
|look in places like:

|This is field 1       Field two starts hereAnd now filed 3      And #4.......
|\____________________/\___________________/\___________________/\_____________

If, indeed, each field occupies a fixed length in the text line, you
can do as follows:

|type

|       myrec = record
|               field1 : string[15]; \
|               field2 : string[40]; |---sample field lengths
|               field3 : string[5];  /
|               .....
|       end;

|var
|       datathing : myrec;
        f : ftext;

begin
   Assign(f,'dummy.text');
   reset(f);
   Total := 0;
   while not eof(f) do with datathing do
begin
   readln(f,field1,field2,field3);
   {do whatever you wish with the data}
   inc(total);
end;

  close(f);
end.

Not compiler-tested, but the concept is correct.

Phil

     The earth is populated by scientists who practice the art of
     infallibility, and non-scientists who are taken in by them.

               (with credit to whomever I copied it from)

2. Oracle Database Monitoring Ideas

3. HELP! read file byte by byte

4. CA-SUNNYVALE-258317--ORACLE-XML-SAP-SUPPLY CHAIN EXPERTS FROM ORACLE SAP XML EXP.

5. Byte by byte read into variables...HOW?

6. recovery fails!

7. Long Varchar and Long Byte

8. Select top

9. Long (integer) vs. Byte

10. Working with strings longer than 255 bytes

11. Found rows longer than 8060 bytes in syscomments

12. HELP:Importing a 4 byte binary field (ULONG) into SQL 7 Int / VB Long

13. OpenIngres long byte bug