Can I use the interop in other .NET languages other than VC++ for .NET.
Absolutely.
But the great power of ManagedC++ (and the reason why I used ManagedC++ in
some project) is that you don't need to use Interop, you could call API
function staright away, just include the header and call the function.
It's great because Interop requires you to redefine the function and its
paramegter in, let's say C#.
Which could be a tedious and error prone process.
Exemple. Let say you want to use GetDeviceCaps()
It's not available in .NET.
In C# you'll have to redecalre it first (prior to use it) like that:
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
but nowehere the nIndex value are defined, so you should open the
PlatformSDK header to find the real number value and maybe declare an enum
like that:
public enum DeviceCap
{
DRIVERVERSION = 0,
TECHNOLOGY = 2,
HORZSIZE = 4,
VERTSIZE = 6,
HORZRES = 8,
VERTRES = 10,
BITSPIXEL = 12,
....
}
A tedious (and error prone) process.
Sometimes you could also find the function declared there:
http://pinvoke.net
Now, what about Managed C++ ?
Well on one hand you could PInvoke in managed C++. But frankly, that's a
waste of
1. processing power (you incure the interop cost doing that)
2. effort
because you could call the function directly as usual:
#include <windows.h>
using namespace System:
rawing;
public ref class ManagedGraphicControler
{
public:
int GetHorizontalRes(Graphics^ g)
{
HDC hdc = (HDC)(void*) g->GetHdc();
int val = GetDeviceCaps(hdc, LOGPIXELSX);
g->ReleaseHdc((IntPtr)(void*)hdc);
return val;
}
}