title: How to import and use functions from .dll to VB.NET? I have solution for this in VBA, but not for VB.NET?
body: <p>I'm newbie in VB.NET. I have some application I have writed in VBA, and now want to transfer to VB.NET.
  There is example how I'm declaring these .dll functions:</p>
  
  <pre class="lang-vba prettyprint-override"><code>Public Declare Function loadsession Lib "vpmsdl32" (ByVal vpmname As String) As Long
  Public Declare Function setvar Lib "vpmsdl32.dll" (ByVal session As Long, ByVal fieldname As String, ByVal value As String) As Long
  Public Declare Function compute Lib "vpmsdl32.dll" (ByVal session As Long, ByVal what As String, ByVal result As String, ByVal result_buffer_size As Long, ByVal message As String, ByVal message_buffer_size As Long, ByVal fieldref As String, ByVal fieldref_buffer_size As Long) As Long
  Public Declare Function closesession Lib "vpmsdl32.dll" (ByVal session As Long) As Long
  Public Declare Function unloadall Lib "vpmsdl32" () As Long
  </code></pre>
  
  <p>I'm using this in VBA code in the way, for example, when I open the session with function loadsession:</p>
  
  <pre class="lang-vba prettyprint-override"><code>session = loadsession("absolute-path-to-the-file")
  </code></pre>
  
  <p>set the input parameters:</p>
  
  <pre class="lang-vba prettyprint-override"><code>ret = setvar(session, "Input name", "Input value")
  </code></pre>
  
  <p>(Hint: I don't have to declare variable <code>ret</code>) after that I perform computing with:</p>
  
  <pre class="lang-vba prettyprint-override"><code>retcomp = compute(session, "Output name", result, 4000, msg, 1000, fieldref, 250)
  </code></pre>
  
  <p>(Hint: I also don't have to declare variable <code>retcomp</code>) After that, I get result of calculation in the variable <code>result</code> (It is not clear for me how it is possible to use variable for calling the function as output variable, for some reasons this function assign result of the computation to variable <code>result</code>, but it works!)</p>
  
  <p>Now, I'm trying to implement the similar way in VB.NET application. First, I perform <code>DLLImport of these functions</code>:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Class PInvoke
  &lt;DllImport("vpmsdl32.dll", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)&gt; _
  Public Shared Function loadsession(ByVal vpmname As String) As Long
  End Function
  
  &lt;DllImport("vpmsdl32.dll", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)&gt; _
  Public Shared Function setvar(ByVal session As Long, ByVal fieldname As String, ByVal value As String) As Long
  End Function
  
  &lt;DllImport("vpmsdl32.dll", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)&gt; _
  Public Shared Function compute(ByVal session As Long, ByVal what As String, ByVal result As String, ByVal result_buffer_size As Long, ByVal message As String, ByVal message_buffer_size As Long, ByVal fieldref As String, ByVal fieldref_buffer_size As Long) As Long
  End Function
  
  &lt;DllImport("vpmsdl32.dll", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)&gt; _
  Public Shared Function closesession(ByVal session As Long) As Long
  End Function
  
  &lt;DllImport("vpmsdl32.dll", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.StdCall)&gt; _
  Public Shared Function unloadall() As Long
  End Function
  End Class
  </code></pre>
  
  <p>and later I call these functions and it works for opening session e.g. <code>PInvoke.loadsession</code>. But I don't know how to access to results of <code>PInvoke.compute</code> function by similar principle I've used in VBA?</p>
  
  <p>Thank you very much for the response!</p>