Good catch on the .lib file, after using C# for a while you tend to forget about stuff like that.
I don't have any where to point you for C++/CLI information other than MSDN. I've learned mostly through trial and error, and various books I've picked up. For the most part managed pointers behave just like native pointers, but they point to a different heap, and you don't need to call delete on them.
As for AfxBeginThread, what I think you're looking for is this:
The managed heap and native heaps are kept seperate, therefore you cannot get a void * to point into the managed heap. What you need to do is copy the struct from the managed to the native heap, then cast your void * and call AfxBeginThread with the pointer to the native heap.
I know it's annoying, but just think about how the memory is physically structured and you'll quickly understand why you need to do this. The overhead should be minimal. G'luck!
Okay... I think I've almost got it... I just need to figure out what delegates are...
Here's what I've done so far:
MATLABDataWrapper is an unmanaged class who holds information I get from calling a MATLAB function
class MATLABDataWrapper
{
public:
//data members... I know these guys should be private, but nobody'll really access em'
mwArray mxInversions;
mwArray mxSample;
mwArray mxTime;
String^ MATLABNamespace::MATLABDataWrapper::toString(void)
{
char buffer[100]; //my data out should never be larger than 100 spaces... I /think/
//annoying hoop to jump through to turn my mwStrings into strings.
sprintf_s ( buffer, 100, "%s\t%s\t%s",
(const char*)this->mxInversions.ToString(),
(const char*)this->mxSample.ToString(),
(const char*)this->mxTime.ToString());
//copy the buffer to a new string? gcnew creates a garbage collected string...
String ^outputStr = gcnew String(buffer,0,100);
/return the garbage collected string, but trim the blanks off the end.
return outputStr->Trim();
}
};
the following is the function that will be used within AfxBeginThread
//must return UINT and can only have one param of type LPVOID
UINT MATLABNamespace::MATLABFunctionThreader::createMATLABThread(LPVOID pointerToDataWrapper)
{
//create a new pointer on the inside the function
//and point it to the data location 'outside'
MATLABDataWrapper *pointer = (MATLABDataWrapper *)pointerToDataWrapper;
//create data arrays
mwArray mxInversions, mxSample, mxTime;
//call MATLAB function
inverterFunction(3, mxInversions, mxSample, mxTime);
//access the memory outside the function,
//and store the data values in appropriate slots.
pointer->mxInversions = mxInversions;
pointer->mxSample = mxSample;
pointer->mxTime = mxTime;
//exit with 'success'
return 0;
}
And here's where I call AfxBeginThread to create my worker thread:
//create a data struct to store data in...
MATLABNamespace::MATLABDataWrapper dataContainer;
//start a worker thread
AfxBeginThread(MATLABNamespace::MATLABFunctionThreader::createMATLABThread,
&dataContainer,//address of data container is passed in as LPVOID
THREAD_PRIORITY_NORMAL); //assume normal thread priority...
Currently my compiler is complaining:
error C3374: can't take address of 'MATLABNamespace::MATLABFunctionThreader::createMATLABThread'
unless creating delegate instance
Aside from not making a delegate, is there anything glaringly wrong with my approach thus far? I think I've done everything right (like creating a pointer on the inside for the separate heap?) But I'm new to this managed code world...
I'll check out the delegate stuff myself, but any tips you wanna send my way would be appreciated as well.