473,385 Members | 1,798 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.

Passing Arrays from VB to C++DLL

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
which variables are passed... no arrays.

However, I am currently working on a routine that
requires that I pass an array to the C++ DLL and then
back again to the main VB program (I actually want to
pass several arrays, but I only want to manipulate one of
them). The C++ routine needs to dynamically resize the
array to sizes that can only be decided during runtime.
In VB this is simply done with ReDim Preserve, but my C++
Bible (Horton's Beginning Visual C++) seems to indicate
that I need to use pointers, duplication, etc. and even
if I get that to work how will VB know that the array has
been resized?

Any assistance is much appreciated - though please keep
your answers at the 'dummies guide' level :-)

Thanks, Kurt
Nov 16 '05 #1
1 3421
If you're going to use Managed Extensions for C++ then any .NET objects can be passed between code written in either language quite easily.

You'll probably want to use System.Collections.ArrayList since it is resizeable (.NET arrays are not). See
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconarraylist.htm
in the Visual Studio help system.

To call functions in C++, create a C++ .NET Class Library project. This will result in a DLL. Add a reference to the DLL in your VB project.

I hope this is clear enough, please reply if you have further questions.

Adam Mitz
Microsoft
--------------------
Content-Class: urn:content-classes:message
From: "Kurt Richardson" <ku**@kurtrichardson.com>
Sender: "Kurt Richardson" <ku**@kurtrichardson.com>
Subject: Passing Arrays from VB to C++DLL
Date: Fri, 25 Jul 2003 15:56:54 -0700
Lines: 28
Message-ID: <1f****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNTAAso3960w0J5SHCP4hLmDy7aXA==
Newsgroups: microsoft.public.dotnet.languages.vc
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26555
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

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
which variables are passed... no arrays.

However, I am currently working on a routine that
requires that I pass an array to the C++ DLL and then
back again to the main VB program (I actually want to
pass several arrays, but I only want to manipulate one of
them). The C++ routine needs to dynamically resize the
array to sizes that can only be decided during runtime.
In VB this is simply done with ReDim Preserve, but my C++
Bible (Horton's Beginning Visual C++) seems to indicate
that I need to use pointers, duplication, etc. and even
if I get that to work how will VB know that the array has
been resized?

Any assistance is much appreciated - though please keep
your answers at the 'dummies guide' level :-)

Thanks, Kurt

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.

Nov 16 '05 #2

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

Similar topics

3
by: Marco | last post by:
Hello there, We're new to C# and have noticed a strange behaviour which we don't yet understand. We wrote a COM DLL (in VC++ 6.0) which performs some calculation based on some double arrays...
4
by: dogalacar | last post by:
Hi All, I am trying to pass array of structures from a C dll to C# as msdn sample does(outarrayofstructs sample) but PtrToStructure function gives error : --> "structure must not be a value...
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...
17
by: mr.resistor | last post by:
hey i am having a few problems calling a C DLL from C#. i am using a simple function that takes an array of floats and an integer as an input, but i cannot seem to get it to work. when i try to...
1
by: dumliks | last post by:
Hi, I have some problems with marshaling data to and from C DLL file; C definitoin for function is: int32 s7_get_multiple_read_cnf( void *od_ptr, /* In call, must be null*/ uint16...
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
9
by: =?Utf-8?B?U2hhcm9u?= | last post by:
In my managed code (C#) I have a some dozens of single dimension byte array. I get each of this arrays from another unmanaged code (first DLL). I need to stitch these arrays to a dual dimensions...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
1
by: fahd | last post by:
Hi, I'm trying to communicate with an unmanaged c++ dll that takes two 2d float arrays, one as input with data in it and the other will have the result of the operation in it as follows: bool...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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:
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,...

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.