I am trying to develop an HMI using VB.Net and have written a webservice that resides on the PPmac to call methods from the C library "libppmac.so" from a remote web application. What appears to be happening is that when I call a method (from a web app or directly from the service) the amount of memory used by the service increases. After a while the C library cannot initialize. Here is how I have written the calls:
P/Invoke statements to call the C function from the library:
Friend Declare Function _InitLibrary Lib "libppmac" Alias "InitLibrary" () As Integer
Friend Declare Sub _CloseLibrary Lib "libppmac" Alias "CloseLibrary" ()
Friend Declare Ansi Function _GetResponse Lib "libppmac" Alias "GetResponse" ( ByVal q As String, ByVal a As StringBuilder, ByVal maxlen As Int32, ByVal echomode As [Byte]) As Integer
Web service method:
_
Public Function GetResponse(ByVal command As String, ByVal echomode As [Byte]) As String
Dim myresponse As New StringBuilder("A", 4096)
Dim mystatus As Integer
Dim initstatus
initstatus = _InitLibrary()
If initstatus = 0 Then
mystatus = _GetResponse(command, myresponse, 255, echomode)
Else
Return "Library did not initalize"
End If
_CloseLibrary()
If mystatus = 0 Then
Return myresponse.ToString
Else
Return GetErrorStr(Math.Abs(mystatus))
End If
End Function
I ran one test where all I did was call InitLibrary() and CloseLibrary() and still had the same issue. I will admit that calling unmanaged code from managed code is new to me so I may just be missing something really simple but I can't figure out what it is. Could I not be closing the library properly?
Thanks.
Update:
The same thing will happen if I use The attribute instead of the P/Invoke method above and each call consumes approx 16M of memory.