【发布时间】:2012-01-05 21:28:45
【问题描述】:
我用 C# 编写了一个 dll,提供了一个类供使用。该 dll 由我编写的 C 程序调用。 (它是一些程序的插件。我必须用 C 编写插件的代码,但我想使用 .NET 的功能,因此是 dll)。
在 dll 中,我想打开一个流并执行其他应该在两次调用 dll 之间保持不变的事情。这在下面的代码中由私有成员 Connector 表示。
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() 时,连接器对象指向 NULL。
当我从我的 C 代码中调用 Timestep() 时,我必须做什么才能访问之前创建的连接器实例?
我可能完全找错了方向。任何提示都表示赞赏。
【问题讨论】:
-
请向我们展示您的 C++ 代码。此外,C != C++。
-
已解决。谢谢大家。感谢 SLaks - 通过我的 C/C++ 代码向您展示它向我展示了错误。 / Stackoverflow 不允许我发布答案,因为我没有收集到足够的声望点。但它会让我在 8 小时内。然后我发布答案。
标签: c# object dll object-persistence