Platform Invocation Services - Examples - A More Complex Example

A More Complex Example

// native declaration typedef struct _PAIR { DWORD Val1; DWORD Val2; } PAIR, *PPAIR; // compiled with /clr, use of #pragma managed/unmanaged can lead to double thunking; // avoid by using a stand-alone .cpp with .h includes // this would be located in a .h file. template<> inline CLR_PAIR^ marshal_as (const PAIR&Src) { // note use of de/referencing, must match your use CLR_PAIR^ Dest = gcnew CLR_PAIR; Dest->Val1 = Src.Val1; Dest->Val2 = Src.Val2; return Dest; }; CLR_PAIR^ mgd_pair1; CLR_PAIR^ mgd_pair2; PAIR native0,*native1=&native0; native0 = NativeCallGetRefToMemory; // using marshal_as, makes sense for large or frequently used types mgd_pair1 = marshal_as(*native1); // direct field use mgd_pair2->Val1 = native0.Val1; mgd_pair2->val2 = native0.val2; return(mgd_pair1); // return to C#

Read more about this topic:  Platform Invocation Services, Examples

Famous quotes containing the word complex:

    All propaganda or popularization involves a putting of the complex into the simple, but such a move is instantly deconstructive. For if the complex can be put into the simple, then it cannot be as complex as it seemed in the first place; and if the simple can be an adequate medium of such complexity, then it cannot after all be as simple as all that.
    Terry Eagleton (b. 1943)