2009-10-21 34 views
2

我在C#等語言中沒有太多經驗,所以如果你們能幫助我,我會很高興。我寫在C++這種方法使用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; 
} 

,現在我想將其導入到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(......); 

我的問題,我不知道該怎麼做。你能幫我嗎?

回答

1

你必須使用structlayout attribute定義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. 
    } 

而且here's how封送一個C裏面的方法++類

[ DllImport(DLL, 
    EntryPoint="[email protected]@@[email protected]", 
    CallingConvention=CallingConvention.ThisCall)] 
    public static extern int TestThisCalling(SchnorrProtocol prot); 
+0

問題是: mpz_class是C++類,這是avalable用: #include 所以標準的運算符和各種標準函數都是overloa讓這個類允許算術。 我不知道如何寫這樣的類的定義。:( – Tatiana 2009-10-21 15:34:59