|
-
August 30th, 2006, 07:47 AM
#1
float __gc[,] to plain old float** ???
Hi again. Simple enough - my C# client passes a float[,] into my managed C++, which needs to pass a float** into a pre-written C function. How?
I'm actually passing a __int16 array too, but I'm not having trouble with that one!
Currently I've got:
Code:
bool GCClass::DoStuff(__int16 Samples __gc[], ..., float TachoSpeeds __gc[,], ...)
{
unsigned int nSamples = Samples->get_Length();
unsigned int nTachos = TachoSpeeds->get_Rank();
unsigned int nTachoSpeeds = TachoSpeeds->GetLength(1); // note that there are no jagged arrays in Managed C++ with .NET framework 2003
// pin managed objects while we copy
GCHandle gchSamples = GCHandle::Alloc(Samples, GCHandleType::Pinned);
GCHandle gchTachoSpeeds = GCHandle::Alloc(TachoSpeeds, GCHandleType::Pinned);
// get pointers to the pinned objects
IntPtr pSamples = gchSamples.AddrOfPinnedObject();
IntPtr ppTachoSpeeds = gchTachoSpeeds.AddrOfPinnedObject();
// go do
bSuccess &= m_lowlevel->InterestingStuff((__int16*)pSamples.ToPointer(), nSamples, ..., (float**)ppTachoSpeeds.ToPointer(), nTachos, nTachoSpeeds, ...);
}
...
bool LowerLevelClass::InterestingStuff(__int16* Samples, unsigned int NumberOfSamples, ..., float** TachoSpeeds, unsigned int NumberOfTachos, ...)
{
// I appear to have to an array of valid float* ptrs but they point to rubbish
}
As noted in the comment of LowerLevelClass::InterestingStuff(), I appear to have an array of float*s but each float* seems to point to rubbish - the debugger says <undefined value> and my attempt (in code) to dereference them blows it up. MSDN implies, though somewhat enigmatically, that pinning any element of an array pins the whole array, so shouldn't pinning TachoSpeeds do the trick?
What am I doing wrong?
Thanks for your time,
Toot
Some cause happiness wherever they go; others, whenever they go.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|