I'm trying to read a shared memory that the software ‘EVEREST Ultimate’ monitoring module uses. They give this example in Delphi, But I need it in vb.net
The shared memory will have xml data like this
I'm not sure if I'm on the right track. One this is that I’m not sure how or what to put in the type library 'senData'
this is the vb.net code I have so far
any help?
Code:
//Delphi
Const
sharedmem_name = 'EVEREST_SensorValues';
Function ExtApp_SharedMem_ReadBuffer(bu:PChar;bu_size:DWord):Boolean;
Var
mappedData : PChar;
th : THandle;
Begin
Result:=False;
th:=OpenFileMapping(FILE_MAP_READ,False,sharedmem_name);
If th<>INVALID_HANDLE_VALUE Then
Begin
mappedData:=MapViewOfFile(th,FILE_MAP_READ,0,0,0);
If mappedData<>Nil Then
Begin
StrLCopy(bu,mappedData,bu_size);
If UnmapViewOfFile(mappedData) Then Result:=True;
End;
CloseHandle(th);
End;
End;
The shared memory will have xml data like this
I'm not sure if I'm on the right track. One this is that I’m not sure how or what to put in the type library 'senData'
this is the vb.net code I have so far
Code:
'vb.net
'not sure what should be in Public Structure
Public Structure senData
Public temp As String
Public id As String
Public label As String
Public value As String
End Structure
Public Const FILE_MAP_READ = &H4
Declare Function UnmapViewOfFile Lib "kernel32.dll" (ByVal lpBaseAddress) As Long
Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Declare Function OpenFileMapping Lib "kernel32.dll" Alias "OpenFileMappingA" (ByVal dwDesiredAccess _
As Integer, ByVal bInheritHandle As Integer, ByVal lpName As String) As Integer
Declare Function MapViewOfFile Lib "kernel32.dll" (ByVal hFileMappingObject As Integer, ByVal _
dwDesiredAccess As Integer, ByVal dwFileOffsetHigh As Integer, ByVal dwFileOffsetLow As Integer, _
ByVal dwNumberOfBytesToMap As Integer) As Integer
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination, ByRef Source, ByVal Length)
Function readmem()
Dim SharedMemHandle
Dim SharedMemPointer
Dim x As senData
SharedMemHandle = OpenFileMapping(FILE_MAP_READ, False, "EVEREST_SensorValues")
If SharedMemHandle Then
SharedMemPointer = MapViewOfFile(SharedMemHandle, FILE_MAP_READ, 0, 0, 0)
'code errors out after next line
CopyMemory(x, SharedMemPointer, Len(x))
'TextBox1.Text = ? ...
End If
UnmapViewOfFile(SharedMemPointer)
CloseHandle(SharedMemHandle)
End Function
any help?