title: Declaring a string of a specific length
body: <p>From Visual Basic I need to call a function in a dynamic link library (DLL) which is implemented in C. The C function has the signature</p>
  
  <pre class="lang-c prettyprint-override"><code>uint32_t F(char **str);
  </code></pre>
  
  <p>where <em>str</em> is an output parameter. The array <code>*str</code> is expected to be at least <em>n</em> characters long. On the Visual Basic side the function is declared as</p>
  
  <pre class="lang-vb prettyprint-override"><code>&lt;DllImport("lib.dll", CallingConvention:=CallingConvention.Cdecl)&gt; _
  Public Shared Function F(ByRef str As String) As UInteger
  End Function
  </code></pre>
  
  <p>How do I declare a string of length <em>n</em> in Visual Basic which is compatible with the formal parameter of the C function <em>F</em>?</p>
  
  <p>Edit: The function call works as expected if I declare the actual parameter as for instance</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim str As String = "          "
  </code></pre>
  
  <p>assuming <em>n</em> is 10. However, <em>n</em> is a variable.</p>