当前位置:编程学习 > C#/ASP.NET >>

懂C#的真的很少呀~~~哎~~

各路英雄哪位能把下边的C#代码转换成托管C++代码~~~

    internal class MyLicenseContext : LicenseContext
    {

        public override LicenseUsageMode UsageMode
        {
            get
            {
                return LicenseUsageMode.Runtime;
            }
        }

        public override string GetSavedLicenseKey(Type type, System.Reflection.Assembly resourceAssembly)
        {
            return "nnnnnnn"; // Insert your license key here!
        }

        public override Object GetService(Type type)
        {
            return null;
        }

        public override void SetSavedLicenseKey(Type type, string key)
        {
        }
  }
--------------------编程问答-------------------- 哎~~~是啊~~~~ --------------------编程问答-------------------- 看着msdn一步一步转 --------------------编程问答-------------------- managed c++只不过是比c++本身多了些符号
别的都一样 --------------------编程问答-------------------- 关键是懂托管C++更少!我自己也试着转换了,没成功!哎自己笨没办法
谁把这个问题给解决了我加分! --------------------编程问答-------------------- 自己顶一下! --------------------编程问答-------------------- --------------------编程问答-------------------- /upload/20131225/2.gif --------------------编程问答-------------------- 俺只是不懂c++ ..... --------------------编程问答-------------------- C++只略懂皮毛!! --------------------编程问答-------------------- 解决方案--不用懂manage c++
1。编译生成DLL
2。开Reflect工具
3。把语言调成manage c++

咔咔,加分。 --------------------编程问答-------------------- 懂C#没人看不懂这段代码的
但是看得懂这段代码的 未必能把它转成托管C++代码的(大多数是不通C++的) --------------------编程问答-------------------- internal class MyLicenseContext : LicenseContext
    {

        public override LicenseUsageMode UsageMode
        {
            get
            {
                return LicenseUsageMode.Runtime;
            }
        }

        public override string GetSavedLicenseKey(Type type, System.Reflection.Assembly resourceAssembly)
        {
            return "nnnnnnn"; // Insert your license key here!
        }

        public override Object GetService(Type type)
        {
            return null;
        }

        public override void SetSavedLicenseKey(Type type, string key)
        {
        }
  }

单从上面这几行代码来说,不过是覆盖了几个方法与属性。
要做到这点,应该没有什么问题,即使你不懂C++。思路如下:
1 LicenseContext基类
这个类的定义是否有C++的版本,如果没有那么是否有类似的?
最差的情况就是要重新自己定义一个。
2 至于上面的那个几个方法覆盖,完全不是问题,不说也应该清楚是怎么回事情。
C++的东西是很多,但要解决这个,需要用到的C++知识应该很少,甚至是很基础的。
解决问题的关键在于那个基础类,不在于你上面提到的这个。 --------------------编程问答-------------------- ding --------------------编程问答-------------------- 用了几年了,就是不太懂。

这算不算是回答楼主呢? --------------------编程问答--------------------
引用 2 楼 sunshine_anycall 的回复:
看着msdn一步一步转

支持这样的说法 --------------------编程问答--------------------
引用 15 楼 wolf1118baby 的回复:
引用 2 楼 sunshine_anycall 的回复:
看着msdn一步一步转 


支持这样的说法


支持 --------------------编程问答--------------------
  不懂。支持一下 --------------------编程问答-------------------- 帮顶~ --------------------编程问答--------------------     class MyLicenseContext : LicenseContext
    {
        public LicenseUsageMode UsageMode = LicenseUsageMode::Runtime;

        virtual public string GetSavedLicenseKey(Type type, System.Reflection.Assembly resourceAssembly)
        {
            return "nnnnnnn"; // Insert your license key here!
        }

        virtual public Object GetService(Type type)
        {
            return null;
        }

        virtual public void SetSavedLicenseKey(Type type, string key)
        {
        }
  }
--------------------编程问答-------------------- 总会有解决的办法的
不是么 --------------------编程问答-------------------- 试着转换了一下,不过有三个敬告不知道怎么去掉。

ref class MyLicenseContext : System::ComponentModel::LicenseContext
{

public:
property System::ComponentModel::LicenseUsageMode UsageMode 
{
virtual System::ComponentModel::LicenseUsageMode get() override
{
return System::ComponentModel::LicenseUsageMode::Runtime;
}
}

virtual System::String^GetSavedLicenseKey(System::Type type, System::Reflection::Assembly resourceAssembly) override
{
return "nnnnnnn"; // Insert your license key here!
}

virtual System::Object ^GetService(System::Type type)override
{
return nullptr;
}

virtual void SetSavedLicenseKey(Type type, String ^key) override
{
}
};

http://www.codeguru.com/forum/archive/index.php/f-17-p-13.html --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 你那几个警告是什么???
建议不在加上virtual了,你没有必要以后扩展类再覆盖一次吧?? --------------------编程问答--------------------
引用 24 楼 gxj760998 的回复:
你那几个警告是什么??? 
建议不在加上virtual了,你没有必要以后扩展类再覆盖一次吧??

用了override就必需用virtual不然编译出错,如果两个关键字都不用就没问题,现在会出现这样的警告,有三个
“override”: 重写说明符的用法不正确;“clr::MyLicenseContext::GetService”与 ref 基类方法不匹配 --------------------编程问答--------------------

ref class Point: public Object
{
protected:
   int x;
   int y;

public:
   Point()
   {
      this->x = 0;
      this->y = 0;
   }

   Point( int X, int Y )
   {
      this->x = X;
      this->y = Y;
   }

   virtual bool Equals( Object^ obj ) override
   {

      //Check for null and compare run-time types.
      if ( obj == nullptr || GetType() != obj->GetType() )
            return false;

      Point ^ p = dynamic_cast<Point^>(obj);
      return (x == p->x) && (y == p->y);
   }

   virtual int GetHashCode() override
   {
      return x ^ y;
   }

};

这是msdn上的代码,不知道为什么这个怎么没有警告? --------------------编程问答-------------------- 看了一下,原来参数要传引用类型,终极版

ref class MyLicenseContext : public  System::ComponentModel::LicenseContext
{

public:
property System::ComponentModel::LicenseUsageMode UsageMode 
{
virtual System::ComponentModel::LicenseUsageMode get() override
{
return System::ComponentModel::LicenseUsageMode::Runtime;
}
}

virtual String ^GetSavedLicenseKey(Type ^type, System::Reflection::Assembly ^ resourceAssembly) override
{
return System::String::Empty;
}

virtual System::Object ^GetService(System::Type ^ type) override
{
return gcnew Object();
}

virtual void SetSavedLicenseKey(System::Type ^type, String ^key) override
{

}
};
--------------------编程问答--------------------
引用 16 楼 mlliqiushi 的回复:
引用 15 楼 wolf1118baby 的回复:
引用 2 楼 sunshine_anycall 的回复: 
看着msdn一步一步转 


支持这样的说法 



支持

00 --------------------编程问答--------------------
引用 10 楼 Deltag1984 的回复:
解决方案--不用懂manage c++ 
1。编译生成DLL 
2。开Reflect工具 
3。把语言调成manage c++ 

咔咔,加分。

应该说是不错的想法
--------------------编程问答-------------------- --------------------编程问答-------------------- 27 楼正确  --------------------编程问答-------------------- c++不懂~
--------------------编程问答-------------------- virtual 
不好意思,我也对C++不熟悉,只是大致知道该如何做。 --------------------编程问答-------------------- 托管C++,吃饱了撑的。
就好象某些人要把C#转换成VB.net

--------------------编程问答-------------------- google一下,有那种转换网站的,把你的代码贴进去然后点击转换即可转成其他语言的代码。
--------------------编程问答-------------------- 这里是原文:大家看下~~

That is the solution: In the class library we have to change the LicenseContext temporarily. Thus we have to create an own class inherited from LicenseContext. This class will return the IC Imaging Control licensekey. It will be set to the LicenseManager.CurrentContext in the constructor.

First of all the LicenseContext inherited class MyLicenseContext. We have to implement four methods:

Code:
    internal class MyLicenseContext : LicenseContext
    {

        public override LicenseUsageMode UsageMode
        {
            get
            {
                return LicenseUsageMode.Runtime;
            }
        }

        public override string GetSavedLicenseKey(Type type, System.Reflection.Assembly resourceAssembly)
        {
            return "nnnnnnn"; // Insert your license key here!
        }

        public override Object GetService(Type type)
        {
            return null;
        }

        public override void SetSavedLicenseKey(Type type, string key)
        {
        }
  }
Second: Usage. In our Classlibrary is a form named "ICForm". On the form we have dragged an IC Imaging Control. Now we have to enhance the constructor of the form as follows:

Code:
        public ICForm()
        {
            LicenseContext SaveContext = LicenseManager.CurrentContext;
            LicenseManager.CurrentContext = new MyLicenseContext();

            InitializeComponent();
            LicenseManager.CurrentContext = SaveContext;
        }
This code saves the current license context, thus other licenses are not disturbed. Then we exchange the current license context with our own license context class. After doing so, the component is initialized (InitializeComponent();) Due to this task, IC Imaging Control is created and licensed with our own license context MyLicenseContext, that returns the correct license key.
After the initialization has been finished, we switch back to the application's license context. 
__________________
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,