Groups | Blog | Home
all groups > dotnet interop > july 2004 >

dotnet interop : Marshaling Fixed Length Strings in Structure


Tom Wells
7/26/2004 4:09:38 PM
I trying to pass this structure to a dll:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Public Structure udtINTER01
<VBFixedString(8), MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)>
Public action As Char()
<VBFixedString(7), MarshalAs(UnmanagedType.ByValArray, SizeConst:=7)>
Public equip_key As Char()
<VBFixedString(256), MarshalAs(UnmanagedType.ByValArray,
SizeConst:=256)> Public message As Char()
<VBFixedString(512), MarshalAs(UnmanagedType.ByValArray,
SizeConst:=512)> Public filler As Char()
End Structure

When I pass it to my dll I get this message:

An unhandled exception of type 'System.ArgumentException' occured in
Test1.exe
Additional Information: Type could not be marshaled because the length
of an embedded array instance does not match the declared length in the
layout

I reviewed the length of each element of the structure and they all
matched the declared lengths.

What does it want??

Brent
7/26/2004 4:13:00 PM
I would not worry about the VBFixedString attribute and try

Brent

[quoted text, click to view]

Tom
7/26/2004 6:30:17 PM
and try ... ??

and try it without the VBFixedString(?) part?

Tom

[quoted text, click to view]
Tom Wells
7/27/2004 7:46:34 AM
Tried it. Doesn't make any difference. I still get the same result.
What does it want?

Tom

[quoted text, click to view]
AddThis Social Bookmark Button