I've been experimenting to see if I can do a managed-unmanaged
transition in C++ using the internal call mechanism - using calli to go
straight
into unmanaged code. Does anyone know if it's possible to do it?

I've managed to get the C++ code to do an indirect calli into
an unmanaged function by using C++ function pointers, but I always
run into the problem that the C++ compiler insists on compiling
my unmanaged function into an IL pinvokeimpl method instead of
into a straight undecorated chunk of native executable instructions
- which I believe means my call still ends up going through P/Invoke.

Code snippets...
#pragma unmanaged
int DoubleIt(int x)
{
    return 2*x;
}
#pragma managed
int _tmain(void)
{
    // this mucking about with w is to stop the compiler optimizing away
    // the fptr function pointer altogether and turning what I want to be
    // a calli into a hardcoded call. Sometimes the C++ compiler can be just
too
    // clever!
    int w;
    int (*fptr)(int);
    w = 34;
    if (w<20)
        fptr = NULL;
    else
        fptr = DoubleIt;

    // OK - this is it...
    int y = fptr(3);

Simon

-----------------------------------------------------------
Simon Robinson
http://www.SimonRobinson.com
-----------------------------------------------------------

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to