473,568 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3434
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.Collecti ons.ArrayList since it is resizeable (.NET arrays are not). See
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 FEB.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**@kurtricha rdson.com>
Sender: "Kurt Richardson" <ku**@kurtricha rdson.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: AcNTAAso3960w0J 5SHCP4hLmDy7aXA ==
Newsgroups: microsoft.publi c.dotnet.langua ges.vc
Path: cpmsftngxa06.ph x.gbl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vc:26555
NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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
4625
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 passed as input parameters to the DLL through the SetParams method defined as follows: interface ICliquet : IPricable
4
8428
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 class" What i am doing wrong ? here is the code
2
4834
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 cmd; short fdc; WORD dsf; short boxcar; short average; short chan_ena;
17
3666
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 compile i get the following error: Attempted to read or write protected memory the C function should not be manipulating the input arra, only...
1
4481
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 *result_array, /* Returned adress of an array of uint16*/ uint16 *var_length_array, /*In call and Returned adress of an array uint16 */ void *value_array /*...
2
4424
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 * len(id) # id is a list of strings Id_dat=StringVector() for i in range(len(Id)): ....Id_dat=id
9
3043
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 array and to be passed to a unmanaged DLL (second DLL) that will change the values of this array. When this unmanaged function returns from the...
17
7226
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 to show the array data to the end user. Can I do that? How?
1
9636
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 Evaluate(float** input,float** output,int nFrames, int featureWidth); note: nFrames and featureWidth will determine the sizes of input and
0
7604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
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. ...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
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...
0
6275
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
932
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...

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.