Hi Guys,
This is the structure:
STRUCTURE A
HeaderType as string ' 2 characters
HeaderVersion As Short ' 100 means version 1.00
Serial As String ' 24 chars
Phone As String ' 12 chars
END STRUCTURE
My VB.NET app will send this structure to a Visual C DLL and this DLL will talk to a UNIX Server. As you know, the DLL and the program on the server side require fixed length of strings.
Suppose:
HeaderType = "10"
HeaderVersion = 100
Serial = "RS001002003004005" ' add spaces so that it is 24 chars
Phone = "123-123-1234"
Marshal and get the pointer by using StructureToPtr (Marshal.StructureToPtr)
Immediately use PtrToStructure, and check the value, it is like this:
HeaderType ="1"
HeaderVersion = 100
Serial = "RS00100200300400" ' add spaces so that it is 24 chars
Phone = "123-123-123"
If check the Hex values, I find the last character of each string is replaced by '\0'.
How could I aviod this?
By the way, I tried to use char array, it did not work; the value received on the server side is incorrect. I tried to increase the size of the string, it did not work as well.
Thanks!
This is the structure:
STRUCTURE A
HeaderType as string ' 2 characters
HeaderVersion As Short ' 100 means version 1.00
Serial As String ' 24 chars
Phone As String ' 12 chars
END STRUCTURE
My VB.NET app will send this structure to a Visual C DLL and this DLL will talk to a UNIX Server. As you know, the DLL and the program on the server side require fixed length of strings.
Suppose:
HeaderType = "10"
HeaderVersion = 100
Serial = "RS001002003004005" ' add spaces so that it is 24 chars
Phone = "123-123-1234"
Marshal and get the pointer by using StructureToPtr (Marshal.StructureToPtr)
Immediately use PtrToStructure, and check the value, it is like this:
HeaderType ="1"
HeaderVersion = 100
Serial = "RS00100200300400" ' add spaces so that it is 24 chars
Phone = "123-123-123"
If check the Hex values, I find the last character of each string is replaced by '\0'.
How could I aviod this?
By the way, I tried to use char array, it did not work; the value received on the server side is incorrect. I tried to increase the size of the string, it did not work as well.
Thanks!