473,385 Members | 1,908 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,385 software developers and data experts.

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


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

*** Sent via Developersdex http://www.developersdex.com ***
Jun 23 '06 #1
1 2334
TDC
You need to use the MarshAs attribute and utilize the SizeConst option
to create a fixed-length array.

HTH,
Tom

Falko wrote:
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

*** Sent via Developersdex http://www.developersdex.com ***


Jun 23 '06 #2

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

Similar topics

3
by: csx | last post by:
Hi all, Ive got a problem with recursion in Javascript. For this tree: http://www.pcm.uklinux.net/structure.jpg If you input node 3 (i.e. C) which is represented as 'values' in the array, it...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
2
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short...
9
by: The Grim Reaper | last post by:
Dear Gurus... (Sorry to cross post... but...) I have a dire problem - been working on this for days now. It's the undocumented API's for NTDLL.dll - namely NtOpenSection, NtMapViewOfSection,...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
10
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I...
1
by: Falko Wagner | last post by:
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...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
11
by: weg22 | last post by:
Hi all, I'm having problems trying to type cast in VB.Net. I'd like to read in a 16 bit unsigned integer and convert it to a signed 16 bit integer. I'm using the following line of code: Dim...
8
webroten
by: webroten | last post by:
I've been working through trying to access a C DLL from VB.NET. I've read many online postings, but I'm still having problems. Now, my error is the "Attempted to read or write protected memory"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.