简体   繁体   English

DllImport和实例化

[英]DllImport and Instantiation

I am newbie in c# and I would apprentice if you could please help me to solve my problem. 我是C#的新手,如果您可以帮助我解决我的问题,我会做徒弟。

I have an un-managed dll which I wrote the following wrapper class to access to its members. 我有一个非托管的dll,我编写了以下包装器类以访问其成员。

unsafe public class EpaNet:IDisposable
    {
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            EpaNet.ENclose();
        }

        [DllImport("epanet2.dll")]
        public static extern int ENepanet(string Inputfile, string ReportFile, string OutputFile,byte[] N );

        [DllImport("epanet2.dll")]
        public static extern int ENopen(string Inputfile, string Reportfile, string Outputfile);

        some other functions ....
}

and to use this class I just write 并使用这个类,我只写

EpaNet.ENopen(...)

This will give me access to the dll members. 这将使我能够访问dll成员。 and when I am running my code in single thread this wrapper works fine. 当我在单线程中运行我的代码时,该包装程序可以正常工作。 The problem begins when I wanna have more than one instance of this dll to run in parallel mode. 当我想拥有多个该dll实例以并行模式运行时,问题就开始了。 since all the members are static therefore in sequential mode I don't need to instantiate but for parallel mode I have to have various instance of this class each working with separate data file and I don't know how to do it. 由于所有成员都是静态的,因此在顺序模式下无需实例化,但对于并行模式,我必须拥有此类的各种实例,每个实例都使用单独的数据文件,而且我不知道该怎么做。

so the question is how to create various instance of EpaNet class? 那么问题是如何创建EpaNet类的各种实例?

Regards, 问候,

e Ë

I think the question is a duplicate of Loading multiple instance of DLL (C#/.NET) 我认为问题是重复加载DLL(C#/。NET)的多个实例

Try to load epanet2.dll from memory. 尝试从内存中加载epanet2.dll。 There's code for it on Github: https://github.com/fancycode/MemoryModule Github上有相关代码: https : //github.com/fancycode/MemoryModule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM