473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What does it want? "... does not match declared length ..."

Tom
I'm getting this error when I try to pass a structure to a dll.

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

What does it mean?
Here's the structure:

<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
I reviewed the length of each element of the structure at runtime and
they all match the lengths in the structure.
I don't want to use ByValTStr because of the trailing null it adds.
I've tried Byte() instead of Char(). No difference.
I've removed VBFixedString(). No difference.

What does it want??

Tom
Nov 20 '05 #1
2 5035
In article <Od**************@TK2MSFTNGP09.phx.gbl>, Tom wrote:
I'm getting this error when I try to pass a structure to a dll.

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

What does it mean?
Here's the structure:

<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
I reviewed the length of each element of the structure at runtime and
they all match the lengths in the structure.
I don't want to use ByValTStr because of the trailing null it adds.
I've tried Byte() instead of Char(). No difference.
I've removed VBFixedString(). No difference.

What does it want??

Tom


Tom, you may need to post some code that is actually using this
defintion. Are you sure that the Pack is neccesary? Can you give the C
definition of the structure and the function that it you're trying to
call. Something odd is going on.

--
Tom Shelton [MVP]
Nov 20 '05 #2
Tom
Tom Shelton wrote:
In article <Od**************@TK2MSFTNGP09.phx.gbl>, Tom wrote:
I'm getting this error when I try to pass a structure to a dll.

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

What does it mean?
Here's the structure:

<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
I reviewed the length of each element of the structure at runtime and
they all match the lengths in the structure.
I don't want to use ByValTStr because of the trailing null it adds.
I've tried Byte() instead of Char(). No difference.
I've removed VBFixedString(). No difference.

What does it want??

Tom

Tom, you may need to post some code that is actually using this
defintion. Are you sure that the Pack is neccesary? Can you give the C
definition of the structure and the function that it you're trying to
call. Something odd is going on.

Tom

Thanks for your replies.

I don't have any C definitions for the dll I'm calling. Here's a
complete module that illustrates the problem. The udtInter01 structure
is the one in question. The commented out udtInter01 structure will not
produce the error but it exhibits the null terminator on fixed length
strings problem (not acceptable in our application). The project imports
System.Runtime.InteropServices.
Module Module1

Declare Function PutServer Lib "myclient32.dll" Alias "PutServer"
(ByRef Control1 As udtControl1, ByVal Fmt As String, ByRef inp As
udtInter01, ByVal InpLen As Integer) As Integer

Structure udtControl1
Dim Memory As Integer
Dim Task As Integer
Dim MessageCode As Integer
Dim ReceivedLength As Integer
Dim RecordCount As Integer
Dim ErrMessageLength As Short
<VBFixedString(320), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=320)> Public ErrMessage As String
<VBFixedString(80), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=80)> Public Reserved As String
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure udtInter01
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> Public
Action As Char()
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=7)> Public
Equip_key As Char()
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)> Public
Message As Char()
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=512)> Public
Filler As Char()
End Structure

'Public Structure udtInter01
' <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=8)> Public
Action As String
' <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=7)> Public
Equip_key As String
' <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Public
Message As String
' <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=512)> Public
Filler As String
'End Structure

Const INTER01_FMT As String = "%s8 %s7 %s256 %s512"
Const INTER01_LEN = 8 + 7 + 256 + 512

Public Sub Main()

Dim Inter01 As udtInter01
Dim Control1 As udtControl1

Inter01.Action = "Get1Equp"
Inter01.Equip_key = "A12345 "
Inter01.Message = Space(512)
Inter01.Filler = Space(256)

PutServer(Control1, INTER01_FMT, Inter01, INTER01_LEN)

End Sub

End Module
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
1
by: Stefan Siegl | last post by:
Hello, I am trying to learn XSLT to use it in another project. I start reading the book "Java and XSLT" and tried the examples and they are went quite fine (how suprising *g*). Then I tried...
0
by: ReignMan | last post by:
I'm running JDK 1.4.0_01, Xalan2.5.1 and Tomcat 4.1.27. XSL transformations work, yet when running in debug mode (Eclipse IDE), I get the following: 990S2html.xsl:3:80: Element type...
15
by: greenflame | last post by:
First of all I only have IE for testing. Ok. I have a script that is supposed to show, not evaluate, the indefinite integral of something. When I run the script it just craches IE. I have tried...
4
by: Alex Sedow | last post by:
Method invocation will consist of the following steps: 1. Member lookup (14.3) - evaluate method group set (Base.f() and Derived.f()) .Standart say: "The compile-time processing of a method...
0
by: LordHog | last post by:
Hello all, I would like to use the new SerialPort class in Visual C++ 2005 Express edition, but I am having problems adding my event handler to the DataReceived event. In the header file I have...
23
by: Rogers | last post by:
I want to compare strings of numbers that have a circular boundary condition. This means that the string is arranged in a loop without an end-of-string. The comparaison of two strings now...
9
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.