私は C# で dll を作成し、使用するクラスを提供しています。dll は、私が作成した C プログラムによって呼び出されます。(これは一部のプログラムのプラグインです。プラグインのコードは C で記述しなければなりませんが、.NET の機能を使用したいため、dll を使用したいと考えています)。
dll では、ストリームを開き、dll への 2 つの呼び出し間で永続化する必要があるその他の処理を実行したいと考えています。これは、プライベート メンバー コネクタによって次のコードで表されます。
namespace myCSharpDll
{
// the c++ program calls this methods
public interface IAccess
{
double Initialize();
double Timestep(double time, double[] values);
...
}
// E is the beginning of another program my dll should connect to, therefore the names
public class EAccess : IAccess
{
// EConnector is another class I defined in the same dll
private EConnector Connector;
public double InitializeE()
{
Connector = new EPConnector();
}
public double Timestep(double time, double[] values)
{
return Connector.Connect();
}
InitializeE() を呼び出し、後で Timestep() を呼び出すと、Connector オブジェクトは NULL を指します。
C コードから Timestep() を呼び出すときに、Connector の作成前のインスタンスにアクセスできるようにするにはどうすればよいですか?
私はおそらくまったく間違った方向に検索します。どんなヒントでも大歓迎です。