... there's no point in pinning a pointer to an unmanaged
object, because the GC doesn't know about these objects and won't move them,
and ignores the pointer. Such blocks of memory are outside its control, just
like a block allocated in an unmanaged program. They are, effectively,
already pinned.
That finally makes sense. I've assumed that if the alloc was done within
managed code, that it would be subject to garbage collection. It's one of
those subtleties that was not clear in the docs that I've read.
The Framework shouldn't interfere with unmanaged-to-unmanaged interactions,
as a rule. It sounds like your application has some very subtle problems.
I'm not sure where to tell you to start, but if you can find an alternative
to interfacing managed and unmanaged code using a mixed-code DLL, this might
be the simplest way to go.
I've heard of subtle bugs in .NET mixed mode in general. It's frustrating
in that so much work went into the mixed mode bridge, and it's difficult
to trace problems. Smaller, or unstressed models of the code work fine.
I thought maybe it was a task prioritization thing, as the access to the
mixed mode code occurs in a thread. Strangely enough, increasing the
thread priority makes the code *less* reliable. I'm not getting runtime
errors or exceptions--just wrong results. Very counterintuitive.
For example, I once did something similar to this
where in the end I ended up driving the C module through a command-line
interface and input/output files. You may also try using PInvoke to call
directly from the managed to the unmanaged code. In C# this is done with the
DllImport attribute; see an example here:
http://msdn.microsoft.com/library/d...s/cscon/html/vctskcodeusingpinvokevisualc.asp
Thanks for the link, Derrick. I first considered PInvoke, but thought
that mixed mode would be better for this app (see below). However, if the
..NET mixed-mode DLL has inherent problems, as in:
http://msdn.microsoft.com/library/d...stechart/html/vcconMixedDLLLoadingProblem.asp
...then I suppose I'll have to give up on it. Unfortunately, the inner C
DLL is very messy, with lots of typedefs and structs that would be tough
to marshal via PInvoke. The fallback plan may be to encapsulate the C DLL
in an unmanaged C++.NET class to simplify the interface, and use PInvoke
to access that.
I've essentially done the encapsulation part already in the course of
writing the mixed-mode DLL, so I suppose I could start from there and
just PInvoke the encapsulating class.
I've also written a completely unmanaged version of the code which works
fine under run-time stress. In other words, I've got lots of clues, all
pointing in different directions. said:
Derrick Coetzee, Microsoft Speech Server developer
Thanks for your perspective, Derrick. My understanding of the
managed-to-unmanaged transition is improving.
Re MS Speech server: I know you're probably more involved with the
ASP-related side of the MS Speech SDK, but I'm curious about MS's 'local'
speech SDK. I haven't had much luck with the 5.1 SDK under .NET. There
was a v5.2 mentioned somewhere that had more .NET support, but it seems to
have disappeared. Do you happen to know if anything new is imminent?
_B