By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

Passing Arrays from VB to C++DLL

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.