Austin Ehlers <th***********************@hotmail.com> wrote in message
news:di********************************@4ax.com...
(I apologize if this is a fairly trivial question, but I mostly use
C#, not MC++.)
We won't hold that against you. :-)
Problem: I've got an unmanaged DLL (and the LIB file), that exports a
bunch of static functions. I'd like to be able to wrap this with a
__gc class, and then access it from C#. All of the examples I've seen
are based upon wrapping unmanaged code (H and CPP files), not existing
DLLs. I'm sure I'm missing something.
Well, I'll explain a couple of ways to attack the problem in the way you
suggest in a moment. But if all you want to do is to call unmanaged code in
a DLL from C# then there may be an easier way. Take a look at this:
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
Back to what you asked:
Of the MS .Net compilers, MC++ stands alone in its ability to compile both
managed and unmanaged code segments in the _same_ module. You delimit those
segments with
#pragma managed
and
#pragma unmanaged
In an unmanaged segment you call DLL exported functions in the usual way.
IJW handles the transitions between managed and unmanaged code invisibly.
So, managed code in a method of a _gc class can call into an unmanaged code
segment which calls a DLL function.
Alternatively, you can use the [DllImport] attribute to declare an external,
static function that resides in a DLL. In most cases, the compiler will
marshall the arguments and make the call without extra work on your part.
Regards,
Will