Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.net Passing a structure to unmanaged dll
    primarykey
    data
    text
    <p>I'm migrating some VB6 code to VB.net, the code contains a structure that contains 1d arrays, 2d arrays, and few other variables.</p> <p>The general outline of the Vb.net structure is as under</p> <pre><code>Public Structure Test Dim a As Single Dim b As Single Dim c As Single &lt;VBFixedArray(2)&gt; Dim arr1() As Single &lt;VBFixedArray(2, 2)&gt; Dim mdarr1(,) As Single &lt;VBFixedArray(4)&gt; Dim arr2() As Byte &lt;VBFixedArray(4)&gt; Dim arr3() As Short &lt;VBFixedArray(3, 2)&gt; Dim mdarr2(,) As Integer Dim d As Integer Dim e As Decimal End Structure </code></pre> <p>The call to the dll is declared as under</p> <pre><code>Public Declare Sub getState Lib "val.dll" (ByRef state As Test) </code></pre> <p><a href="https://stackoverflow.com/questions/2919048/passing-a-structure-containing-an-array-of-string-and-an-array-of-integer-into-a">Elsewhere</a> on this site I realized that we have to "marshal" the structure to allow it to be compatible with the unmanaged code that is about to accept it.</p> <p>However I still receiving runtime errors when running the code, I don't have any clue of how to use the <code>System.Runtime.InteropServices.Marshal</code> class.</p> <p>What would be the correct way to pass this structure to the dll?</p> <p><strong>EDIT:</strong></p> <p>The original VB6 data type is</p> <pre><code>Public Type Test a As Single b As Single c As Single arr1(0 To 2) As Single mdarr1(0 To 2, 0 To 2) As Single arr2(0 To 4) As Byte arr3(0 To 4) As Integer mdarr2(0 To 3, 0 To 2) As Long d As Long e As Currency End Type </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload