Note that there are some explanatory texts on larger screens.

plurals
  1. POCall Win32 DLL from .NET with complex struct
    primarykey
    data
    text
    <p>I have upgraded an old VB6 component to .NET. This component made a call to another Win32 component, with the following type structure:</p> <pre><code>Public Type DDPARAMS bAddressFlag As String * 1 bCompanyFlag As String * 1 bNameFlag As String * 1 bPremiseFlag As String * 1 ..etc </code></pre> <p>I cannot reference this Win32 DLL as it is not a COM DLL, so .NET can't create any interop for me automatically.</p> <p>I have the original source for the Win32 DLL (written in C), and the struct is defined here as:</p> <pre><code>typedef struct tagDDPARAMS { BYTE bAddressFlag; BYTE bCompanyFlag; BYTE bNameFlag; BYTE bPremiseFlag; BYTE sPremiseThreshold[3]; etc. </code></pre> <p>When I upgrade the VB6 component, the .NET code generated for the struct is:</p> <p>Public Structure DDPARAMS Public bAddressFlag() As Char </p> <pre><code> &lt;VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1)&gt; Public bCompanyFlag() As Char &lt;VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1)&gt; Public bNameFlag() As Char &lt;VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=1)&gt; Public bPremiseFlag() As Char &lt;VBFixedString(3), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=3)&gt; Public sPremiseThreshold() As Char &lt;VBFixedString(3), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=3)&gt; Public sLooseThreshold() As Char </code></pre> <p>etc.</p> <p>However, when I run this code, I get the following error:</p> <p><strong><em>Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout.</em></strong></p> <p>I have googled and googled and am out of ideas - any help is appreciated.</p> <p>UPDATE: I tried the suggestion below and changed ByValArray to AnsiBStr (one byte string) and now get the following:</p> <p><strong><em>"Cannot marshal field 'sTown' of type 'DDRECORD': Invalid managed/unmanaged type combination (Arrays fields must be paired with ByValArray or SafeArray)."</em></strong></p> <p>Thanks a lot Duncan</p>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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