473,666 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PROBLEM PASSING ARRAY OF STRUCTURE TO VC++ DLL

Hi Friends ,

Could anyone please help me to resolve the following issue :

I pass an array of structures to a dll written in VC++ 6.0 whih fills
it with data . The following works well for VB 6.0 but when I wrote
the same piece of code in VB 2005
the array of structures remained empty even after the API call :

I have a structure as follows :

Structure tree_struct
Dim level As Short
Dim branch_id As String
Dim s_desc As String
Dim parent_id As String
Dim access As Short
Dim flag As Short
Dim branch_desc As String
End Structure

My declaration statement looks like following :

Declare Function fetch_tree_hier archy Lib "mydll.dll" (ByVal
tree_handle As Short, ByVal app_id As String, ByRef l_tree_struct() As
tree_struct) As Short

Following is a sub written in VB 2005 which calls the above function
"fetch_tree_hie rarchy " present in a dll "mydll.dll" written in vc++
6.0 :

Dim i As Integer = 0

Dim l_tree_struct() As tree_struct
ReDim l_tree_struct(1 00)

retcode = vb_get_menu_hie rarchy(tree_han dle, "app_id",
l_tree_struct)

If retcode = SUCESS Then

Console.WriteLi ne("Get Tree Hierarchy Succeeded")

Else

GetErrorText(re tcode) 'Is a function which maps error
codes to error text
Call terminate_all()
Exit Sub

End If

In above case the Array of structure is coming empty.

Some Progress , Still No Results

During my exploration of various possibilities I went through an
example given at Microsoft website and did the following changes to
my above code :
<StructLayout(L ayoutKind.Seque ntial, CharSet:=CharSe t.Ansi)Public
Structure tree_struct
Dim level As Short
Dim branch_id As String
Dim s_desc As String
Dim parent_id As String
Dim access As Short
Dim flag As Short
Dim branch_desc As String
End Structure
Public Class LibWrap
Declare Function fetch_tree_hier archy Lib
"tcvbodss.d ll" (ByVal mnu_handle As Short, ByVal apl_id As String,
ByRef outArray As IntPtr) As Short
End Class

Dim outArray As IntPtr
LibWrap.vb_get_ menu_hierarchy( tree_handle, "app_id",
l_tree_struct)
Dim manArray(100) As vb_menu
Dim current As IntPtr = outArray
Dim i As Integer

For i = 0 To 100 - 1

manArray(i) = New tree_struct

Marshal.PtrToSt ructure(current , manArray(i))

Marshal.Destroy Structure(curre nt, GetType(tree_st ruct))

current = IntPtr.op_Expli cit(current.ToI nt64() +
Marshal.SizeOf( manArray(i)))

Console.WriteLi ne("Element {0}: {1} {2}", i,
manArray(i).bra nch_id, manArray(i).bra nch_desc)

Next i

Marshal.FreeCoT askMem(outArray )

At line : " Marshal.PtrToSt ructure(current , manArray(i))" I am getting
following exception :

Message : Value cannot be null.
Parameter name: ptr

My mistake may be quite silly as I am new to VB 2005 , kindly help me
to resolve this problem.

Sincerely,

Sudhansu

Aug 31 '07 #1
2 2845
>I pass an array of structures to a dll written in VC++ 6.0 whih fills
>it with data . The following works well for VB 6.0 but when I wrote
the same piece of code in VB 2005
the array of structures remained empty even after the API call :

Can you post the working VB6 code so we can compare?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Aug 31 '07 #2
On Aug 31, 10:55 pm, Mattias Sjögren <mattias.dont.w ant.s...@mvps.o rg>
wrote:
I pass an array of structures to a dll written in VC++ 6.0 whih fills
it with data . The following works well for VB 6.0 but when I wrote
the same piece of code in VB 2005
the array of structures remained empty even after the API call :

Can you post the working VB6 code so we can compare?

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.ne t/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
Hi Mattias ,

Thanks a lot for the reply , following is the working VB 6 code for
your reference :

Type tree_struct
Dim level As Integer
Dim branch_id As String
Dim s_desc As String
Dim parent_id As String
Dim access As Integer
Dim flag As Integer
Dim branch_desc As String
End Type

My declaration statement looks like following :

Declare Function fetch_tree_hier archy Lib "mydll.dll" (ByVal
tree_handle As Integer, ByVal app_id As String, ByRef l_tree_struct()
As tree_struct) As Integer
Dim retcode As Integer

Dim l_tree_struct(1 00) As tree_struct

retcode = fetch_tree_hier archy(tree_hand le, "app_id",
l_tree_struct)

Sincerely,

Sudhansu

Sep 3 '07 #3

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

Similar topics

0
4195
by: Linux Inquirer | last post by:
Hi Guys, I need to pass a C structure of this form from VB6 <-> VC++ 6 struct BTag { int rowIndex; BSTR* valueList; } B;
32
2146
by: Carson | last post by:
Hi , Is there a very efficient way to set a double array to 0 ? (I have tried memset, but the result doesn't look correct.) Carson
11
2059
by: Tatu Portin | last post by:
I have a struct: typedef struct { char **user_comments; int *comment_wds; int comments; char *vendor; } vorbis_comment;
2
2189
by: david | last post by:
Well, as a matter of fact I_HAD_MISSED a basic thing or two, anyway, although Ollie's answer makes perfectly sense when dealing with classes, it doesn't seem to me to apply as well if you have to instantiate an array of structures; consider the following useless code : using System; struct MyPointS
1
3438
by: Kurt Richardson | last post by:
Hi all Sorry to bother you with what is probably a really trivial question for you C++ experts. My programming skill are pretty amateur, but I'm pretty good at VB.NET. However, I'm wanting to realise some of the speed benefits of writing some of my routines in C++ and accessing them from my VB software. I have managed to do this with a few simple routines in
3
1401
by: project | last post by:
Hi every body, Any body can help me the following doubts? 1. what is constructor? 2. what is destructor? 3. what is overriding function. 4. different between structure and array 5. what is objected oriented
3
1757
by: Steve | last post by:
Hello, I created a public Structure in a Standard Module and also an array of Structures. Then I load data into the array of structures in a public sub that I call on the Form load event. Next I have a class, and I want to pass a structure member from my array of Structures to the class constructor. In the form I instantiate a class object. Module1
2
2097
by: George | last post by:
Hi all, I have VB applicatoin , which calls a function in VC++ DLL Arguement of function is a one dimensional string array. Array will get filled in VC++ dll function. I have written the programme given below.
13
3195
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the functions that require a structure to be passed to them. The function declaration in the .h file is of the form: SDCERR GetConfig(char *name, SDCConfig *cfg); where SDCConfig is a structure defined in the .h file. I am not much of a C (or C#)...
0
8444
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8869
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8639
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.