[re 'flat model / C++ interop' bridge to unmanaged DLL]
On Mon, 10 Jan 2005 10:14:01 -0500, "Nicholas Paldino [.NET/C# MVP]"
<(E-Mail Removed)> wrote:
> The example isn't going to be that complex, I am afraid. Actually, you
>don't even need code to show how to call the C code from the unmanaged C++
>code. The issue is properly handling the unmanaged C++ class (since it is
>allocated on the unmanaged heap, etc, etc.).
> Because your class will have an unmanaged resource in it (the unmanaged
>C++ class), you should implement the IDispose interface, so that the Dispose
>method can be exposed, and the class can be cleaned up correctly.
I've done all unmanaged mem management (ahem) inside the unmanaged C++
wrapper. I haven't used 'dispose', as I manually keep track of all the
alloc'd memory. I don't think that's the problem, especially in that
there are only a couple large buffers that need to be accounted for. I'll
give that another look, but the code problems occur before the dealloc of
any objects.
The problem IS that the bridge between unmanaged and managed is somewhat
of a black box to me. I don't have time on this project to study the
Marshal class as thoroughly as I'd like, nor to review the sparse examples
that I've seen for 'flat model'. I'm afraid I'm missing something.
Despite that, the only thing I'm passing between managed/unmanaged is a
few pointers, and the code that I was drawing from did not use Marshal for
transfering simple (int, short) types.
The other puzzling thing is that failures are intermittent. It would seem
that (short of a sweep of the memory manager) they should either fail or
succeed. The failure rate seems independent of machine speed or amount of
available ram.
With enough study time and clues, I'd be able to solve this easily, but
unfortunately, the project manager doesn't have much patience for a
methodical approach.
> For more information on doing this sort of thing, check out the section
>of the .NET framework titled "Managed Extensions for C++ Migration Guide",
>located at (watch for line wrap):
>
>http://msdn.microsoft.com/library/de...nagedtypes.asp
Thanks for the pointer.
> Also, if you have time, and think that you can use the CLI extensions
>(as managed extensions are going out the window),
!? Uh-oh. I've done a search for CLI Extensions and come up with only a
handful of google hits. Is this part of VS 2005, or is it something that
is currently accessible?
Thanks, Nicholas.
B