473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Argumen tException' 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(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi, Pack:=1)> _
Public Structure udtINTER01
<VBFixedString( 8), MarshalAs(Unman agedType.ByValA rray, SizeConst:=8)>
Public action As Char()
<VBFixedString( 7), MarshalAs(Unman agedType.ByValA rray, SizeConst:=7)>
Public equip_key As Char()
<VBFixedString( 256), MarshalAs(Unman agedType.ByValA rray,
SizeConst:=256) > Public message As Char()
<VBFixedString( 512), MarshalAs(Unman agedType.ByValA rray,
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 5057
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.Argumen tException' 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.Sequ ential, CharSet:=CharSe t.Ansi, Pack:=1)> _
Public Structure udtINTER01
<VBFixedString( 8), MarshalAs(Unman agedType.ByValA rray, SizeConst:=8)>
Public action As Char()
<VBFixedString( 7), MarshalAs(Unman agedType.ByValA rray, SizeConst:=7)>
Public equip_key As Char()
<VBFixedString( 256), MarshalAs(Unman agedType.ByValA rray,
SizeConst:=256) > Public message As Char()
<VBFixedString( 512), MarshalAs(Unman agedType.ByValA rray,
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.Argumen tException' 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.Seq uential, CharSet:=CharSe t.Ansi, Pack:=1)> _
Public Structure udtINTER01
<VBFixedString( 8), MarshalAs(Unman agedType.ByValA rray, SizeConst:=8)>
Public action As Char()
<VBFixedString( 7), MarshalAs(Unman agedType.ByValA rray, SizeConst:=7)>
Public equip_key As Char()
<VBFixedString( 256), MarshalAs(Unman agedType.ByValA rray,
SizeConst:=25 6)> Public message As Char()
<VBFixedString( 512), MarshalAs(Unman agedType.ByValA rray,
SizeConst:=51 2)> 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 ErrMessageLengt h As Short
<VBFixedString( 320), MarshalAs(Unman agedType.ByValT Str,
SizeConst:=320) > Public ErrMessage As String
<VBFixedString( 80), MarshalAs(Unman agedType.ByValT Str,
SizeConst:=80)> Public Reserved As String
End Structure

<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)> _
Public Structure udtInter01
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=8)> Public
Action As Char()
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=7)> Public
Equip_key As Char()
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=256) > Public
Message As Char()
<MarshalAs(Unma nagedType.ByVal Array, SizeConst:=512) > Public
Filler As Char()
End Structure

'Public Structure udtInter01
' <MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=8)> Public
Action As String
' <MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=7)> Public
Equip_key As String
' <MarshalAs(Unma nagedType.ByVal TStr, SizeConst:=256) > Public
Message As String
' <MarshalAs(Unma nagedType.ByVal TStr, 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_k ey = "A12345 "
Inter01.Message = Space(512)
Inter01.Filler = Space(256)

PutServer(Contr ol1, 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
6515
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 FRICKIN' COOL!!! ***MAN*** that would save me a buttload of work and make my life sooooo much easier!" As opposed to minor differences of this feature...
70
8818
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 expression should equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why? Can anyone help me? Thanks. Best regards. Roy
1
2798
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 to adopt these examples to my files. Unfortunately I did not work even though the styleSheet is very simple. Perhaps you can help me with it.
0
5135
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 "xsl:stylesheet" must be declared. 990S2html.xsl:11:3: Element type "xsl:output" must be declared. 990S2html.xsl:12:25: Element type "xsl:template" must...
15
2131
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 to get all the obvious bugs out... Um... The script is at: http://ali.freezope.org/idf test and what it is supposed to show is at:...
4
1492
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 invocation of the form M(A), where M is a method group and A is an optional argument-list, consists of the following steps:  The set of candidate...
0
1875
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 the method that will handle the event defined as private: void SerialPortReceive_EventHandler( System::Object ^ sender,...
23
2073
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 becomes a different operation than with regular strings because the circular string can be "rotated", like this: 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 4 5 1...
9
27608
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 patterns(words). What it does is takes a string as a parameter, determines length of string, tests if the length is a perfect square, if it is then it makes a 2-d...
0
7711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7467
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.