次の方法で C++ dll があります。
//C++ dll method (external)
GetServerInterface(ServerInterface* ppIF /*[OUT]*/)
{
//The method will set ppIF
}
//ServerInterface is defined as:
typedef void * ServerInterface;
C# プロジェクトから dll にアクセスするために、C++/CLI プロジェクトを作成し、マネージド クラスを次のように宣言しました。
public ref class ComWrapperManager
{
//
//
ServerInterface _serverInterface;
void Connect();
//
//
}
以下に示すように、Connect() メソッドを使用して GetServerInterface を呼び出します。最初の呼び出しは機能しますが、2 番目の呼び出しは機能しません。誰かが理由を説明できますか?そのポインターをマネージ クラスのメンバー変数として永続化する必要があります。これを行うより良い方法はありますか?
void Connect()
{
ServerInterface localServerInterface;
GetServerInterface(&localServerInterface); //THIS WORKS
GetServerInterface(&_serverInterface); //THIS DOESNT
//Error 1 error C2664: 'ServerInterface ' :
//cannot convert parameter 1 from //'cli::interior_ptr<Type>'
//to 'ServerInterface *'
}