Data marsing for C #

I have little experience in a language like C #, so I would be glad if you guys could help me. I wrote this method in C ++ using the MPIR library:

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 in 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 dont know how to do it. Could you help me?

+2


source to share


1 answer


You have to use structlayout attribute to define mpz_class, i.e.

  [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

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

      

+1


source







All Articles