ninjaneer 1 Junior Poster in Training

Hello again, daniweb.

I have created a managed C++ GUI using windows forms that needs to call some functions in an unmanaged C++ DLL that was created by the MATLAB compiler.

The functions from the MATLAB compiler need to be run in their own thread in the background while input is recorded from the GUI.

Currently I've got the MATLAB DLL created and the GUI is 100%, but when I call my unmanaged function from my managed code I get the following error box:

Debug Assertion Failed!
Program:...
File: dbgheam.c
Line:1414

Expression: _CrtIsValidHeapPointer(pUserData)

...

I know that the code that is creating this error are between the managed and umanged portions and I also know that they're due to the two different stacks that memory is on. I just don't know how to get memory from one stack to another. Two weeks of googling and struggling has yielded no solution.

the following is my unmanaged code, and it's location just above my Windows Form definition

/*this is the beginning of my file... given to show you where I've defined my unmanaged code -- just in case I'm doing it wrong*/
#pragma once

namespace MATLABDemonstration {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::Threading;



//here is where my unmanaged code is defined
 #pragma unmanaged

	public class MATLABDLL{
	public:
void MATLABFunctionCall()
{
    mxDouble mathworksDoubleArray[6];
		
	mwArray output(1, 6, mxDOUBLE_CLASS, mxREAL);
	mwArray input(1, 1, mxDOUBLE_CLASS,mxREAL);

	inverterFunction(1, output);

	output.GetData(mathworksDoubleArray, 6);
		
	for(int i = 0; i <= 5 ; i++)
	 *(outputContainer + i) = (double)mathworksDoubleArray[i];
  }
MATLABDLL(){}
~MATLABDLL(){}
double outputContainer[6];

	};

 #pragma managed
//managed windows Form GUI definitions start here...

And here is the managed section that calls the unmanaged code. It is inside a function that is called when a button is pressed on the GUI.

if(initializeMATLABDLL())
		 {

		  MATLABDLL test;
		  test.MATLABFunctionCall();

		  for(int i = 0 ; i<=5 ; i++)
			  consoleScreen->AppendText(test.outputContainer[i].ToString());

		  startPauseButton->Text = "Pause";

		 }

I know I've got to somehow copy outputContainer between the two stacks... I just don't know how to do it.