我已经在C#中编写了一个dll,提供了一个可供使用的类。该DLL由我编写的C程序调用。 (它是一些程序的插件,我必须用C语言编写插件的代码,但我想使用.NET的功能,因此是dll)。如何在C#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()时,Connector oject指向NULL。
我有什么做的,当我打电话时步()从我的C代码,我可以访问连接的创建之前实例?
我大概是在错误的方向搜索。任何提示都表示赞赏。
请向我们展示您的C++代码。另外,C!= C++。 – SLaks
已解决。谢谢大家。感谢SLaks - 通过我的C/C++代码向你展示给我看的错误。/Stackoverflow不让我发布答案,因为我没有收集到足够的声望点。但它会让我在8小时内。然后我发布答案。 – Teetrinker