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