2009-10-21 4 views
2

C#과 같은 언어로 된 경험이 많지 않으므로 도와 주시면 기쁘게 생각합니다. 나는 MPIR 라이브러리를 사용하여 C에서이 방법 ++ 썼다 :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(......); 

내 문제는 내가 그것을 할 방법을 모르겠어요. 너 나 좀 도와 줄래? avalable입니다 mpz_class는 C++ 클래스 :

답변

1

당신은 ++ 클래스에게 당신이 C 내부의 방법을 마샬링 here's how

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

문제입니다, 즉 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. } 

structlayout attribute를 사용하고 있습니다 다음을 포함합니다 : #include 표준 연산자와 다양한 표준 함수가 overloa입니다. 이 클래스로 산술 연산을 허용하려면 ded. 나는 그런 종류의 정의를 쓰는 방법을 모른다 :. – Tatiana