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 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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
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
|
by: Tatu Portin |
last post by:
I have a struct:
typedef struct {
char **user_comments;
int *comment_wds;
int comments;
char *vendor;
} vorbis_comment;
|
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
|
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
| |
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
|
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
|
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.
|
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#)...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |