2017-03-16 5 views
1

が、私はこの方法(.NET Frameworkの2.0)私はマネージCからそれを呼び出したいC++/CLIおよび.NETうち、文字列のC#で

public String Authenticate(String configUrl, out String tokenId) 

++コード を持ってPARAMTER私は

__authenticator->Authenticate( gcnew System::String(hostUrl),gcnew System::String(temp)); 
を持っています

ですが、tokenIdがtrueに戻ります。

私は、C#で^%の使用に関するいくつかの答えを見てきましたが、それはちょうどコンパイルされません。

+0

は 'http://stackoverflow.com/見る(ないC++/CLIコンパイラによって、refoutの違いは唯一のC#コンパイラによって確認された何かであることに注意してください)temp2outであることを知っていますa/187577/613130' ...しかし、ここで何が問題なのですか? 'temp'と' hostUrl'は何ですか?あなたは何を期待していますか? – xanatos

答えて

1

[OK]を私は考える(同等の、C#で、私は^

CString hostUrl; 
String^ temp ; 
String^ error = __authenticator.get() == nullptr ? "failed to get token" : 
       __authenticator->Authenticate( gcnew System::String(hostUrl),temp); 
3

public String Authenticate(String configUrl, out String tokenId) 

この

__authenticator->Authenticate(
    gcnew System::String(hostUrl), 
    gcnew System::String(temp) 
); 

あるで文字列を渡すパラメータを作成し、それを得ましたAuthenticateの署名)〜

__authenticator.Authenticate(
    new String(hostUrl), 
    out new String(temp) 
); 

が、C#であなたがする必要がありますので、あなたは...変数、フィールドにout new Something、あなたができる唯一のoutを行うことはできませんC#で:

String temp2 = new String(temp); 

__authenticator.Authenticate(
    new String(hostUrl), 
    out temp2 
); 

と、パラメータがであることを考慮outすることができます:

String temp2; 

__authenticator.Authenticate(
    new String(hostUrl), 
    out temp2 
); 

さて、C++/CLIで、あなたが持っている

System::String^ temp2 = gcnew System::String(temp); 

__authenticator->Authenticate(
    gcnew System::String(hostUrl), 
    temp2 
); 

または、

// agnostic of the out vs ref 
System::String^ temp2 = nullptr; 

// or knowing that temp2 will be used as out, so its value is irrelevant 
// System::String^ temp2; 

__authenticator->Authenticate(
    gcnew System::String(hostUrl), 
    temp2 
); 
関連する問題