C# ^什么意思
System::Int32^ nCSharp = 20;
System::Int32 nNum;
nNum = nCSharp;
这个东西为什么编译不通过
错误 1 error C2440: “=”: 无法从“System::Int32 ^”转换为“int” d:\Projects\ArrStringTest\ArrStringTest.cpp 36 我想用用C#写dll 然后VC调用 可以C#中的方法返回的是 xxxx结构的^类型 我如何把这个变量转换为xxxx类型呢 就如上面的那个例子
顺便问一下 在VC调用C#的DLL数据时 有没有什么好办法可以更方便转换呢 我现在用的是对每个数据结构进行一个一个的定义拷贝函数方法

解决方案 »

  1.   

    ^在C# 中是exclusive-OR 操作符。
    看你的代码应该是Manager C++而不是C#
    在Manager C++中^是执行托管对象的指针。
    例子:
    // mcppv2_handle.cpp
    // compile with: /clr
    ref class MyClass {
    public:
       MyClass() : i(){}
       int i;
       void Test() {
          i++;
          System::Console::WriteLine(i);
       }
    };int main() {
       MyClass ^ p_MyClass = gcnew MyClass;
       p_MyClass->Test();   MyClass ^ p_MyClass2;
       p_MyClass2 = p_MyClass;   p_MyClass = nullptr;
       p_MyClass2->Test();   
    }参考:
    http://msdn.microsoft.com/en-us/library/yk97tc08(VS.80).aspx
      

  2.   

    你的程序可以改成:
    System::Int32^ nCSharp = 20; 
    System::Int32 nNum; 
    nNum = *nCSharp; System::Console::WriteLine(nNum);
    System::Console::Read();
      

  3.   

    Manager C++应该可以直接使用C#的dll的。
    不明白你说要copy是什么意思,最好举个例子。
      

  4.   

    写了点测试代码,你可以参考一下:
    C#
    namespace ClassLibrary1
    {
        public class Class1
        {
            public static MyData GetObject()
            {
                return new MyData();
            }
        }    public class MyData
        {
            public int a = 4;
            
            public string b = "hello";    }
    }C++ MyData^ d = ClassLibrary1::Class1::GetObject(); System::Console::WriteLine(d->a);
    System::Console::WriteLine(d->b);
    System::Console::Read();