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

dynamic array as a byref parameter

dynamic array as a byref parameter by used in function and
have a Marshal error ,what is the matter?thanks

source like as this .
------------------------------------------------------
Declare Function finit Lib "DllCap.dll" _
(ByRef rdAcnt As ACNTINF2) As Integer

<StructLayout(LayoutKind.Sequential)> Structure ACNTINF
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=16)> Dim
subid As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=40)> Dim
subname As String
End Structure

<StructLayout(LayoutKind.Sequential)> Structure ACNTINF2
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=10)> Dim
acntnum As String
<MarshalAs(UnmanagedType.LPStruct)> Dim actInfo() As
ACNTCNT
End Structure

Private Sub FORM1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim rdAcnt2 As ACNTINF2
Dim iRtn As Integer
iRtn = finit(rdAcnt2)
End Sub
Nov 20 '05 #1
2 2447
"xinsir" <ze*********@newtouch.com.cn> schrieb
dynamic array as a byref parameter by used in function and
have a Marshal error ,what is the matter?thanks

source like as this .
------------------------------------------------------
[source]


If you won't get an answer here, there is also
microsoft.public.dotnet.framework.interop
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
In article <2e****************************@phx.gbl>, xinsir wrote:
dynamic array as a byref parameter by used in function and
have a Marshal error ,what is the matter?thanks

source like as this .
------------------------------------------------------
Declare Function finit Lib "DllCap.dll" _
(ByRef rdAcnt As ACNTINF2) As Integer

<StructLayout(LayoutKind.Sequential)> Structure ACNTINF
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=16)> Dim
subid As String
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=40)> Dim
subname As String
End Structure

<StructLayout(LayoutKind.Sequential)> Structure ACNTINF2
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=10)> Dim
acntnum As String
<MarshalAs(UnmanagedType.LPStruct)> Dim actInfo() As
ACNTCNT
End Structure

Private Sub FORM1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Dim rdAcnt2 As ACNTINF2
Dim iRtn As Integer
iRtn = finit(rdAcnt2)
End Sub


You didn't specify the error, but I your main problem is that your
trying to pass an array of structs inside of a structure. The current
marshaler dose not support that. You will want to change the ACNTINF2
structure to look like this:

<StructLayout(LayoutKind.Sequential)> _
Structure ACNTINF2
<MarshalAs(UnmanagedType.ByValTStr, sizeconst:=10)> _
Dim acntnum As String
Dim actInfo As IntPtr
End Structure

And then use the properties of the Marshal class to actually access the
array. The methods you would most likely be needing are Marshal.SizeOf
and Marshal.PtrToStructure.

This is air code... But the process would look something like:

dim st as acntinf
dim ptr as intptr = acnt2.actInfo

for i as integer = 0 to numberofelements
' get the current structure
st = ctype(marshal.ptrtostructure(ptr, GetType(ACNTINF)), ACNTINF)

' process st

' increment the pointer to the next value
ptr = new IntPtr(ptr.ToInt32() + Marshal.SizeOf(GetType(ACNTINF)))
next i

You may have to do things differently, since I'm not sure how you tell
with this particular function the size of the array. I could be more
specific if I knew more about the actual call :)

--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #3

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

Similar topics

1
by: Derek Hart | last post by:
I have the following code: Me.GetType().InvokeMember(FunctionToRun, BindingFlags.InvokeMethod, Nothing, Me, params) I can send in a string from a database into the FunctionToRun variable, and...
8
by: Peter B. Steiger | last post by:
The latest project in my ongoing quest to evolve my brain from Pascal to C is a simple word game that involves stringing together random lists of words. In the Pascal version the whole array was...
8
by: Eyeawanda Pondicherry | last post by:
I have put some code together that creates an enum dynamically from some database values. The enum can be read perfectly by an application that references the dynamically generated dll. If I...
19
by: Rob Panosh | last post by:
Hello, Ok here is the senerio: ..... Dim myArrayList as New ArrayList(0) me.Test_A( myArrayList )
4
by: Warren Sirota | last post by:
Hi, Please let me know if I am interpreting this correctly. I've done a little testing of the difference between passing parameters byVal and byRef, and the results were slightly non-intuitive,...
4
by: Erik Foreman | last post by:
this is what I have 'variables defined as arrays Dim ceday(), ceti(), ceto(), ceproj(), cenotes() As String Dim cerow As Int32
6
by: ari | last post by:
hey all, i have the following 2 classes: Public Class DataAccessLayer .... .... Public Sub GetRecords(ByRef ds As DataSet1) ds = New DataSet1
0
by: vinbelgian | last post by:
I have some trouble with making a buffer in vb.net. I use a C dll that requires me to give him a pointer to a buffer of bytes where he is going to write bytes to, depending on the command i...
3
by: Troy | last post by:
I have a dilemma where I am creating a dynamic two dimensional array and filling it with information from a .csv file. Unfortunately, later when I try to call that information back from the array...
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
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
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...
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,...
0
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...
0
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,...

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.