Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens if/when DllImport is invoked multiple times?

I am loading a .dll written in Delphi 7 using DllImport within a Windows service written in C# .NET 4. Before deploying this service, I just want to make sure that I don't have to do anything special to handle the unmanaged .dll.

My C# code looks something like this:

[DllImport("MyDelphiDLL.dll")]
private static extern string DoSomething(string value);

private void SomeMethod(List<string> values)
{
    foreach (string value in values)
    {
        string newValue = DoSomething(value);
    }
}

The DoSomething function will be called multiple times, and I suspect that MyDelphiDLL.dll only gets loaded either when the managed .dll gets loaded, or upon the first reference to DoSomething, but I'm not really sure.

I have looked at the DllImportAttribute Class documentation at MSDN, but it doesn't really state one way or the other. I've also searched SO, and Googled the question every way that I can think of, and still haven't found a definitive answer.

I just want to make sure I go about this correctly.

like image 365
Welton v3.61 Avatar asked Feb 23 '23 20:02

Welton v3.61


1 Answers

There no problem with what you're doing. The DLL will be loaded once and will stay loaded.

like image 134
Steve Morgan Avatar answered Mar 01 '23 23:03

Steve Morgan