Click here to Skip to main content
15,895,839 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am trying to expose a Managed Function to Unmanaged Code using C++/CLI wrapper
C++
public:array<double, 3>^ CallingBrownianManagedCodeTemp()
{
   int numPaths = 100;
   int dimension = 3;
   double time = 30;
   int seed = 1;
   double stepSize = 1.0 / 12.0;
   int scrambling = 0;
   array<double, 2>^ covMatrix = { { 1.0, 0.0, 0.0 },							 { 0.0, 1.0, 0.0 },							 { 0.0, 0.0, 1.0 } };		   
   std::string str = "Sobol";
   String^ newSystemString = gcnew String(str.c_str());
			   			   
   array<double, 3>^ result = (array<double, 3>^)    IAModel::RandomNumberGenerator::iBrownianBridge(numPaths, dimension, time, seed, covMatrix, stepSize, newSystemString, scrambling);
			   
return result;
}

__declspec(dllexport) void CallBrownianManagedAdapter(double*** myArray)
{	
 BrownianWrapper::BrownianBridgeAdapter objectBrownian;
 array<double, 3>^ brownianArray  = objectBrownian.CallingBrownianManagedCodeTemp();	
}


I need to copy the contents of brownianArray (Managed Array Dynamic) to Unmanaged array which is myarray. I do not mind vector also. I was trying to declare a vector but the program won't recognize the vector in CLI.

I am new to C++, appreciate any suggestion

What I have tried:

stackoverflow.

It works in C#
Posted
Comments
Sergey Alexandrovich Kryukov 11-Apr-16 17:24pm    
Why your managed function is not static (an instance function)? This is the whole issue. If you create an instance of the class BrownianBridgeAdapter each time you call the unmanaged function, what could possibly be its purpose?
—SA
devender_t 14-Apr-16 20:39pm    
Hi Sergey, This is a third party library I've no control over it. I am able to successfully call the function which returns the managed array. How can I move copy the data into an unmanaged 3d array or vector. I was thinking to create double*** myArray. I need to figure out if it works

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