Problems with structure in structure and DLL function call in VB.NET

F

Falko Wagner

Hi there,

I am currently translating a VB 6.0 application to .NET and have the
following problem:

The data structure I need to pass to a DLL function call has a structure
variable inside its structure:

Private Structure CstData_type
Dim Cst_AZ As DbLong
Dim Cst_DECKS As DbLong
Dim Cst_LUZ As DbSingle
Dim Cst_ZoneLen As ZoneSingleArray
End Structure

where

Private Structure ZoneSingleArray
Dim ZoneArr(20) As DbSingle
End Structure

The Function call of the DLL is declared as

Private Declare Function ShPlcDb_Rd_Data
Lib "D:\ShPLCDb\ErShPlcDb.dll"
Alias "_ShPlcDb_Rd_Data@24"
(ByVal nSubSysNode As Integer,
ByVal nDataType As Integer,
ByVal nDataIdx As Integer,
ByVal nDataCnt As Integer,
ByRef pData As "Any",
ByVal nDataLen As Integer) As Integer

Note the 5th parameter in the function call (pData) is declared
originally as Any (VB6.0).

Now, if I use the directive <StructLayout(LayoutKind.Sequential)> to
declare the struct and change the type of the 5th parameter in the
function call from Any to CstData_type, the function call works fine up
until the last variable in the struct Cst_ZoneLen. If I leave it out, it
works. If I put the last variable in the declaration, I get the error
message:

System.TypeLoadException
Additional information: Can not marshal field Cst_ZoneLen of type
CstData_type: The type definition of this field has no layout
information.

I have tried to declare the Structure ZoneSingleArray with
<StructLayout(LayoutKind.Sequential)> as well, but that didn't do the
trick. I get the same error.

Question: How should I declare the data structure so it works with my
DLL?

Looking forward to any suggestions!

Falko
 
C

Cor Ligthert [MVP]

Falko,

Typical a question for our specialist about that Wagner, I don't know if he
will be again active today but than probably late. (I know there are more
who knows this)

:)

However I will try it as well. There has been a shift in the values.

A vb6 integer is now an int16
A vb6 long is now an int32
A vb6 short now a int16

Maybe it helps so far,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top