Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good morning,

I am working on a project which use C# code, a C\CLI wrapper and C++ code. Actually, I have to call an managed function inside a C++ function.
My function in C++ has this prototype :
C++
void TestArray(float** array1, int numRows, int numCols);


Inside this function I call a C# function which has this prototype :
C#
public void TestArray(ref float[,] arrayTest, int numRows, int numCols);


I created in the C++ function TestArray a cli::array which contains the data of the array "array1" and after I passed to the C# function. See below the code :
C++
cli::array<float,2>^ array1_test = gcnew cli::array<float,2>(numRows,numCols); 
...
//Call the C#function 
TestArray(array1_test, numRows, numCols );

But by using this way, I used lot of copy I guess and I would like to know if it is possible to use the address of the array (the one passed in argument by float**) and passed this one directly to the C# function.

Thank you in advance for any suggestions.
Posted

1 solution

This article with code example may be of interest to you:
Unmanaged Arrays in C# - No Problem[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900