To actually implement code that uses managed constructs, you should add another source file and set the following compiler switches:
• C/C++ > Precompiled Headers > Create/Use precompiled headers: Set this property to Use precompiled header /Yu.
• C/C++ > Precompiled Headers > Precompiled header file: Set this property to $(IntDir)\$(TargetName)_clr.pch.
• C/C++ > General > Compile with CLR Support: Set this property to Common Language Runtime Support /clr.
• C/C++ > Code Generation > Basic Runtime Checks: Set this property to Default.
• C/C++ > Code Generation > Enable Minimal Rebuild: Set this property to No.
• C/C++ > Code Generation > Enable C++ Exceptions: Set this property to Yes with SEH exceptions /EHa.
Once you have a project with files compiled to managed code as well as files compiled to native code, you need to call functions compiled to managed code from functions compiled to native code and vice versa. As mentioned in Chapter 1, function declarations and type declarations are sufficient to call from native to managed code and vice versa. Chapter 9 discusses all internals of function calls with managed/unmanaged transitions.
Was this article helpful?