We are trying to communicate between our two applications, One is in
VB.Net and the other one is in ruby.How to communicate between a ruby
and .Net application?
Below is a sample code written to create a Memory Mapped File in VB.Net
Public Shared Sub WriteData()
Try
'String to write in memory
Dim str As String = "This is a test data for Non-Persisted
Memory Mapped File."
Dim bytes As Byte()
'Convert the string to bytes
bytes = StrToByteArray(str)
'To store all bytes with length of bytes at 0 position
Dim bytesnew = New Byte(bytes.Length) {}
'Storing the length at first(0) position
bytesnew(0) = bytes.Length
'Copying all the bytes after the length
For i As Integer = 1 To bytes.Length
bytesnew(i) = bytes(i - 1)
Next
'Calculating the size of file with 1 extra byte for storing
length of bytes.
Dim filesize As Integer = bytes.Length + 1
'Creating a new file in memory
Using file = MemoryMappedFile.CreateNew("myFile", filesize)
'Creating a accessor that maps to the view of memory
mapped file(MMF)
Using writer = file.CreateViewAccessor(0, filesize)
'Writing the bytes in memory
writer.WriteArray(Of Byte)(0, bytesnew, 0, filesize)
End Using
MsgBox("File written in memory, Now read file without
clicking OK button.")
'MMF will get automatically disposed after this line due
to using statement.
End Using
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
’ VB.NET to convert a string to a byte array
Public Shared Function StrToByteArray(ByVal str As String) As Byte()
Dim ByteArr As Byte() = Nothing
Try
Dim encoding As New System.Text.UTF8Encoding
ByteArr = encoding.GetBytes(str)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return ByteArr
End Function
After creating the Memory Mapped File through the above code how can we
read/write it in ruby?
Any help will be greatly appreciated.
Regards, Premjeet Singh