locked
How to convert unmanaged ptr (*) to managed reference (^) RRS feed

  • Question

  • Hi,
     My managed function require (IAbc^) and i'm having it's pointer. How should i convert IAbc* to to IAbc^?


    Example -->
    Unmanaged Code:
    unmanagedFun( IAbc* ab)
    {
        managedFun( /* how should i pass IAbc* here */);
    }

    Managed Code:
    managedFun (IAbc^ abc)
    {
    }

    Thanks in advance
    Wednesday, November 26, 2008 11:35 AM

Answers

  •  I got the answer -

    unmanagedFun( IAbc* ab)
    {

            Object^ o = Marshal::GetUniqueObjectForIUnknown(IntPtr(ab));

            IAbc^ refIAbc = safe_cast<IAbc^>(o);

            managedFun( refIAbc );
    }


     

    • Marked as answer by Interop Thursday, November 27, 2008 12:36 PM
    Thursday, November 27, 2008 6:11 AM