简体   繁体   English

C#的封送数据

[英]Marshalling data for C#

I have not many experience in such language as C# so I would be pleased if you guys could help me. 我在C#这样的语言方面经验不足,所以如果您能帮助我,我将非常高兴。 I wrote this method in C++ using MPIR library: 我使用MPIR库在C ++中编写了此方法:

mpz_class SchnorrProtocol::getX(const mpz_class& r) const
{
    mpz_class x;
    mpz_powm(x.get_mpz_t(), this->params_.getBeta().get_mpz_t(), r.get_mpz_t(), this->params_.getP().get_mpz_t());
    return x;
}

and now I want to import it to C#: 现在我想将其导入到C#中:

  #region Filter & P/Invoke
#if DEBUG
        private const string DLL = "schnorrd.DLL";
#else
       private const string DLL = "schnorr.DLL";
#endif

        [DllImport(DLL)]
  "method definition"
        ......  SchnorrProtocol::getX(......);

my problem, I don't know how to do it. 我的问题,我不知道该怎么做。 Could u please help me? 你能帮我吗?

You have to use structlayout attribute to define mpz_class, ie, 您必须使用structlayout属性定义mpz_class,即

  [StructLayout(LayoutKind.Explicit, Size=16, CharSet=CharSet.Ansi)]
   public class mpz_class 
   {
      // your class definition
   }

  [StructLayout(LayoutKind.Explicit, Size=16, CharSet=CharSet.Ansi)]
   public class SchnorrProtocol 
   {
           // your class definition.
   }

And here's how you marshal a method inside a C++ class 这就是在C ++类中封送方法的方式

[ DllImport( DLL, 
    EntryPoint="?getX@SchnorrProtocol@@QAEHH@Z", 
    CallingConvention=CallingConvention.ThisCall )]
    public static extern int TestThisCalling( SchnorrProtocol prot ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM