How to address C++/CLI managed/unmanaged from C#?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RostKudr
    New Member
    • Dec 2010
    • 3

    #1

    How to address C++/CLI managed/unmanaged from C#?

    My attemption with MS Visual Studio 2008 SP1.
    Compilng/linking is OK. But the run of Main.exe results in FileNotFoundExc eption (HRESULT: 0x8007007E) in TestUnmanaged.M ain.
    Code:
    // cl /clr /LN Sub.cpp
    using namespace System;
    #pragma unmanaged
    void Dummy () {;}
    #pragma managed
    namespace MySubSpace {
      ref class Sub1 {
        public:
          void SaySub1 (String ^name) {
            Console::WriteLine ("Sub1 says : {0}", name);
            Dummy ();
        }
      };
    }
    // csc Main.cs /addmodule:Sub.netmodule /platform:x86
    using System;
    using MySubSpace;
    public class TestUnmanaged {
      public static void Main () {
        Sub1 s1 = new Sub1();
        s1.SaySub1 ("from Main");
      }
    }
    Main.exe runs successfully if four lines in Sub.cpp with "pragma" and "Dummy" are commented out and "cl /clr:safe /LN Sub.cpp" is applied.
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    I dn't know much about it, but I know, there's an unsafe keyword in c#, maybe you have a look at it

    msdn 1
    msdn 2

    Comment

    • RostKudr
      New Member
      • Dec 2010
      • 3

      #3
      Thanks, Christian. But not any of the manipulations with "unsafe" in Main.csc prevents the exception.
      I've tried:
      1. public unsafe static void Main ()
      2. csc Main.cs /addmodule:Sub.n etmodule /platform:x86 /unsafe+
      3. 1st and 2nd together.

      The exception throws even if there is only one line in the method Main: Sub1 s1;

      Comment

      • RostKudr
        New Member
        • Dec 2010
        • 3

        #4
        The problem is soldved in MS Visual Studio 2010 with applying csc compiler's key /unsafe

        Comment

        Working...