473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB.net to C++ WORD help

I'm sending a message from VB.net (2003) to a C++ app via TCP sockets of
values 1 to 328. The message is a WORD value where I have to manage both
bytes for the WORD. I'm sending and receiving data from the C++ app with no
problem between the values of 1 to 127 and 256 to 328, but the application
receives garabage between 128 and 255. My current test syntax is as follows:

Dim nodeid As Integer = CType(txtMessage.Text, Integer)

Dim nodes(5) As Char
nodes(0) = Chr(7) '<- 1st WORD, Message Type = 7 in low bit
nodes(1) = Chr(0) '<- 1st WORD, high bit is off
nodes(2) = Chr(6) '<- 2nd WORD, Length of message = 6
nodes(3) = Chr(0) '<- 2nd WORD, high bit off

'Here is where I'm having the problem:
'1-127 in the low bit works great. (nodes(4) = 127, nodes(5) = 0 ) =
127
'256 to 328 works great. (nodes(4) = 0, nodes(5) = 1) = 256

'I'm not sure how to use 128 through 255 for this message
nodes(4) = ChrW(nodeid) '3rd WORD, if we exceed 255 need to push
high bit
nodes(5) = Chr(0) '1 if greater than 256
Send(nodes)
Private Sub Send(ByVal sendData() As Char)
Try
Dim writer As New StreamWriter(MyClient.GetStream)
writer.Write(sendData)
writer.Flush()
Catch ex As Exception
Throw ex
End Try

Any help would be greatly appreciated, thanks.
End Sub
Dec 27 '05 #1
1 1633
Hi,

"Sisnaz" <Si****@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.com...
I'm sending a message from VB.net (2003) to a C++ app via TCP sockets of
values 1 to 328. The message is a WORD value where I have to manage both
bytes for the WORD. I'm sending and receiving data from the C++ app with
no
problem between the values of 1 to 127 and 256 to 328, but the application
receives garabage between 128 and 255. My current test syntax is as
follows:
When using binary data then don't use Chars, String or StreamWriter, it will
only complicate things. When a StreamWriter uses ASCII encoding it will
convert any chars >127 to a question mark.

MemoryStream ms = new MemoryStream(6);
ms.Write( BitConverter.GetBytes(Convert.ToUint16(7)), 0, 2 )
ms.Write( BitConverter.GetBytes(Convert.ToUint16(6)), 0, 2 )
ms.Write( BitConverter.GetBytes(UInt16.Parse(txtMessage.Text )), 0, 2 )

SendBinary( ms.ToArray() )

Private Sub SendBinary(ByVal Data() As Byte)
MyClient.GetStream().Write(Data,0, Data.Length)
End Sub

You could also use a BinaryWriter instead of using a BitConverter.
Offcourse, endianess on both sides is important too, so if they don't match,
you can wrap the GetBytes in a Array.Reverse.
HTH,
Greetings


Dim nodeid As Integer = CType(txtMessage.Text, Integer)

Dim nodes(5) As Char
nodes(0) = Chr(7) '<- 1st WORD, Message Type = 7 in low bit
nodes(1) = Chr(0) '<- 1st WORD, high bit is off
nodes(2) = Chr(6) '<- 2nd WORD, Length of message = 6
nodes(3) = Chr(0) '<- 2nd WORD, high bit off

'Here is where I'm having the problem:
'1-127 in the low bit works great. (nodes(4) = 127, nodes(5) = 0 )
=
127
'256 to 328 works great. (nodes(4) = 0, nodes(5) = 1) = 256

'I'm not sure how to use 128 through 255 for this message
nodes(4) = ChrW(nodeid) '3rd WORD, if we exceed 255 need to push
high bit
nodes(5) = Chr(0) '1 if greater than 256
Send(nodes)
Private Sub Send(ByVal sendData() As Char)
Try
Dim writer As New StreamWriter(MyClient.GetStream)
writer.Write(sendData)
writer.Flush()
Catch ex As Exception
Throw ex
End Try

Any help would be greatly appreciated, thanks.
End Sub

Dec 28 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Roys | last post by:
Hi Im doing something wrong in quitting the Word.Application in my VB program. I have General Declarations Dim AppWord As Word.Application Form_Load() Set AppWord =...
8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
3
by: Ronny Sigo | last post by:
Hello all, Could anybody give me the correct syntax to set the : line indent, top margin cursor position in Ms Word, with VBA ? Thanks !!! Ronny Sigo .... Here's what I have done so far,...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
10
by: Neil | last post by:
An article at http://news.com.com/2100-1012-991694.html?tag=fd_top states: "XML would allow easier interchange of data generated in Office documents with back-end systems or existing Web...
8
by: sudha | last post by:
Hi, To open a word doc from c#, i use the following code : Word.ApplicationClass WordApp = new Word.ApplicationClass (); // give any file name of your choice. object fileName =...
0
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather...
1
by: apondu | last post by:
Hi, can someone help me and provide me the information on how to supress the default action of the shortcut keys of word during word automation. I am using C#.Net I have written a code but...
1
by: beanie | last post by:
i am a c programming beginner and i am trying to Create a concordance of Word Count for a text File in c programming but my code isn't working.please can u help me out.here is my code: #include...
5
by: alivip | last post by:
How can I get every Token (word) and PreviousToken(Previous word) From multube files and frequency of each two word my code is trying to get all single word and double word (every Token (word) and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.