What's wrong with this?

J

JamesB

Dim enc As New System.Text.ASCIIEncoding
If enc.GetString(GetStr) = "GET" Then
Dim GetURL() As Byte
Sys.Marshal.Copy(pPkt, GetURL, OffsetRes + 4, 32)
WebPage = enc.GetString(GetURL) 'Mid(enc.GetString(GetURL), 1,
InStr(enc.GetString(GetURL), "HTTP"))
End If

When stepping through the code, it highlights the sys.marshal.copy... line
and then skips back up to the top. No errors etc.

pPkt is an IntPtr containing a TCP Packet. This section of code is only
called if 3 bytes come out as "GET" as a string. (I am trying to pull out
the following data to get the actual web resource being used)
 
J

JamesB

JamesB said:
Dim enc As New System.Text.ASCIIEncoding
If enc.GetString(GetStr) = "GET" Then
Dim GetURL() As Byte
Sys.Marshal.Copy(pPkt, GetURL, OffsetRes + 4, 32)
WebPage = enc.GetString(GetURL) 'Mid(enc.GetString(GetURL), 1,
InStr(enc.GetString(GetURL), "HTTP"))
End If

When stepping through the code, it highlights the sys.marshal.copy... line
and then skips back up to the top. No errors etc.

pPkt is an IntPtr containing a TCP Packet. This section of code is only
called if 3 bytes come out as "GET" as a string. (I am trying to pull out
the following data to get the actual web resource being used)

Extra info - Im actually getting an error (if i put that in a try.catch
block) of destination cannot be nothing.
So I think the problem is that my

dim GetURL() as byte

isn't actually creating an object? If so, how do I do that.
I tried dim GetURL() as new byte, and a few other combinations but all give
compliation errors.
 
L

Larry Lard

JamesB said:
So I think the problem is that my

dim GetURL() as byte

isn't actually creating an object? If so, how do I do that.
I tried dim GetURL() as new byte, and a few other combinations but all give
compliation errors.

Well, it's in the docs, but in short: Array variables in VB.NET are
object variables, so like any other object variables they are Nothing
until you give them something to point to. There are a number of ways
to actually *define* arrays but what you want is probably just

Dim GetURL() As Byte = New Byte(100) {}

where 100 is how long you want the array to be (small gotcha here). The
{} is the array initializer which here is empty which will result (for
an array of Byte) in an array full of 0s.
 
J

JamesB

Well, it's in the docs, but in short: Array variables in VB.NET are
object variables, so like any other object variables they are Nothing
until you give them something to point to. There are a number of ways
to actually *define* arrays but what you want is probably just

Dim GetURL() As Byte = New Byte(100) {}

where 100 is how long you want the array to be (small gotcha here). The
{} is the array initializer which here is empty which will result (for
an array of Byte) in an array full of 0s.

Hmm, embarassingly I had read that somewhere but it obviously didn't sink
in.
I'm now getting that the data extends beyond the end of the array (that will
be your gotcha) so I have something to play with.
Thanks for simplifiying it!
James.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top