473,765 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple Question - Passing Arrays to Functions

I need to pass an array from C# to a managed C++ function (that will
in turn call unmanaged C code). My knowledge of managed C++ syntax is
limited (obviously). This needs to be a reference parameter so the
function can change the contents of the array and give it back to the
caller.

How should I declare this array parameter in the managed C++ function?

Feb 25 '07 #1
2 3577
By 'managed' do you mean C++/CLI?
If so, then the following example accepts an integer array by ref:
void Foo(array<int^% ThisArray)
{
}
But, unless you are changing the array reference, the following will do:
void Foo(array<int^T hisArray)
{
}
You do not have to pass by ref if just changing the contents of an array
since the array reference is not changing.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
"Rich" wrote:
I need to pass an array from C# to a managed C++ function (that will
in turn call unmanaged C code). My knowledge of managed C++ syntax is
limited (obviously). This needs to be a reference parameter so the
function can change the contents of the array and give it back to the
caller.

How should I declare this array parameter in the managed C++ function?

Feb 25 '07 #2
On Feb 25, 8:10 am, David Anton <DavidAn...@dis cussions.micros oft.com>
wrote:
By 'managed' do you mean C++/CLI?
If so, then the following example accepts an integer array by ref:
void Foo(array<int^% ThisArray)
{}

But, unless you are changing the array reference, the following will do:
void Foo(array<int^T hisArray)
{}

You do not have to pass by ref if just changing the contents of an array
since the array reference is not changing.
--
David Antonwww.tangib lesoftwaresolut ions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter

"Rich" wrote:
I need to pass an array from C# to a managed C++ function (that will
in turn call unmanaged C code). My knowledge of managed C++ syntax is
limited (obviously). This needs to be a reference parameter so the
function can change the contents of the array and give it back to the
caller.
How should I declare this array parameter in the managed C++ function?- Hide quoted text -

- Show quoted text -
PERFECT - That is exactly what I needed. Thanks very much!

Feb 25 '07 #3

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

Similar topics

31
14346
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? Basically: "Press any key to continue..." I beleive that I am looking for is something along the lines of a....
4
49247
by: Suddn | last post by:
Help me get my mind around passing string types to a function. I need to have the function modify the string types and get them back. Normaly I would just return the modified string but I need to modify about five different strings. I thought that strings were passed by reference in C/C++ but when I pass the strings in they remain unaltered in the calling function. I did test the function being called and they are being althered there.
12
6558
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
58
10179
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
2
1971
by: dave.harper | last post by:
I'm relatively new to C++, but have a question regarding functions and arrays. I'm passing a relatively large array to a function several thousand times during the course of a loop, and it seems to get bogged down. Do the arrays previously passed to the function stay memory resident? If not, what's causing it and what can I do to correct it? Thanks, Dave
10
3170
by: Pete | last post by:
Can someone please help, I'm trying to pass an array to a function, do some operation on that array, then return it for further use. The errors I am getting for the following code are, differences in levels of indirection, so I feel it must have something to do with the way I am representing the array in the call and the return. Below I have commented the problem parts. Thanks in advance for any help offered. Pete
6
12659
by: DeepaK K C | last post by:
Could anybody tell me how to pass array to a function by value? -Deepak
11
8128
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
24
3458
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
2
1728
by: nleahcim | last post by:
Hi - I am working on writing a number of matrix manipulation functions. The most basic one was a printing algorithm - and it shows the problem I'm having. I'm passing it a pointer a mutidimensional array (matrix) as well as the number of rows and columns. Problem is I don't know what type the pointer to the multi-dimensional matrix should be. Right now it's an int * and it works just fine, but when I call the function I get a warning...
0
9568
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
10161
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...
1
9955
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9833
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
8831
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...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3924
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
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
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.