0

I am on the way of learning java and I wanted to know what is the System.load(dll) parallel/ implementation of this in C#..is it like the "using" statement? I am a c# developer so maybe by having an example it will be better for me to understand it

3 Answers3

1

In java :to Load a Java Native/Dynamic Library (DLL) , see this example :

import com.chilkatsoft.CkZip;

public class Test {

  static {
    try {
        System.load("C:/chilkatJava/chilkat.dll");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[]) 
  {
    CkZip zip = new CkZip();
    System.out.println(zip.version());    
  }
}

In C#: try this link Answer :https://stackoverflow.com/a/1087851/1743852

Community
  • 1
  • 1
Alya'a Gamal
  • 5,624
  • 19
  • 34
1

In C# you can use Reflection to load library dynamically in runtime:

System.Reflection.Assembly myDllAssembly = 
   System.Reflection.Assembly.LoadFile("%MyDLLPath%\\MyDLL.dll");

After that you'll be able to search for types from that assemble:

System.Type MyDLLFormType = myDllAssembly.GetType("MyDLLNamespace.MyDLLForm");

And create object of that type:

Form MyDLLFormInstance = (Form)myDllAssembly.CreateInstance("MyDLLNamespace.MyDLLForm");
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
0

In C#, you cannot load a native dll, instead you P/Invoke them!

P/Invoke, or Pinvoke stands for Platform Invocation Services. PInvoke is a feature of the Microsoft .NET Frameowrk that allows a developer to make calls to native code inside Dynamic Link Libraries (DLL’s). When Pinvoking, the .NET framework (or Common Language Routine) will load the DLL and handle the type conversions automatically. The most common use of P/Invoke is to use a feature of Windows that is only contained in the Win32 API. The API in Windows is extremely extensive and only some of the features are encapsulated in .NET libraries.

Parimal Raj
  • 20,189
  • 9
  • 73
  • 110