How to examine the first 32bits of a string in vb.net

  • Thread starter Thread starter VBS Programer
  • Start date Start date
V

VBS Programer

I am working with a thermal printer that returns it's status in a string. In
vb6.0 I would use the MidB,AscB functions to examine the first 32 bits. What
can I use in vb.net to do the same.
 
VBS Programer said:
I am working with a thermal printer that returns it's status in a string. In
vb6.0 I would use the MidB,AscB functions to examine the first 32 bits. What
can I use in vb.net to do the same.

What *exactly* do you mean by "the first 32 bits"? You need to talk in
terms of characters, not bits when it comes to text data. Use Substring
to get parts of the string.
 
I have a function that return a pointer to 32bits of data from the printer.
The code I am using to get that data into my program is "
pOutData = Marshal.PtrToStringAnsi(pCscDhlPara.pOutData) ". as per the
printer developer. The variable pOutData is defined as "string =
space(2048)". I now need to examine the data "32bits" that was returned.
 
VBS Programer said:
I have a function that return a pointer to 32bits of data from the printer.
The code I am using to get that data into my program is "
pOutData = Marshal.PtrToStringAnsi(pCscDhlPara.pOutData) ". as per the
printer developer. The variable pOutData is defined as "string =
space(2048)". I now need to examine the data "32bits" that was returned.

Hmm. If it's really binary data, marshalling it as a string sounds like
a really bad idea. What's the type of pCscDhlPara.pOutData?
 
The structure is defined as

Structure CscDhlPara
Dim hCsc As Int32
Dim Spec As Int32
Dim InLen As Int32
Dim pInData As IntPtr
Dim OutLen As Int32
Dim pOutData As IntPtr
Dim StClass As Int32
Dim StCode As Int32
Dim StWarn As Int32
Dim StAction As Int32
End Structure

Thanks for your time.
 
VBS Programer said:
The structure is defined as

Structure CscDhlPara
Dim hCsc As Int32
Dim Spec As Int32
Dim InLen As Int32
Dim pInData As IntPtr
Dim OutLen As Int32
Dim pOutData As IntPtr
Dim StClass As Int32
Dim StCode As Int32
Dim StWarn As Int32
Dim StAction As Int32
End Structure

Thanks for your time.

I would suggest using Marshal.ReadInt32(IntPtr) then - that should read
the first 32 bits of data at the right place.
 
I have tried
Marshal.ReadIntPtr(pCscDhlPara.pOutData, pOutData)

with pOutData defined as Integer, but it seem always to return 0. How would
I check the bits of an Intger?
 
I have also tried ReadInt32 and still get zero

VBS Programer said:
I have tried
Marshal.ReadIntPtr(pCscDhlPara.pOutData, pOutData)

with pOutData defined as Integer, but it seem always to return 0. How
would I check the bits of an Intger?
 
VBS Programer said:
I have also tried ReadInt32 and still get zero

If ReadInt32 is returning zero, I'm not sure what's wrong. You need to
find out *exactly* what's going to be at the memory location returned.
Marshalling it as text seems like a very bad idea to me, but without
knowing more about the details, it's hard to know why ReadInt32 isn't
working.

You might want to ask on the interop group too - they may well be able
to help you more.
 
Thank you for your time, Jon.

Jon Skeet said:
If ReadInt32 is returning zero, I'm not sure what's wrong. You need to
find out *exactly* what's going to be at the memory location returned.
Marshalling it as text seems like a very bad idea to me, but without
knowing more about the details, it's hard to know why ReadInt32 isn't
working.

You might want to ask on the interop group too - they may well be able
to help you more.
 
Back
Top