Implementing methods for loading DLLs and calling their functions in C # text

Source: Internet
Author: User
Here is a small series to bring you a C # load DLL and call its function implementation method. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

In C # programming, calling functions in encapsulated DLLs is used at high frequencies. So how do you load a DLL in a program and call a function in it? Further, how do you debug the functions in your own encapsulated DLL in the main program?

Load dll-Add Reference

Adding a reference means getting the program to load the corresponding DLL according to the configured path when it is generated. The steps they refer to are as follows:

Solution, reference, add Reference, browse, select the path of the DLL, OK

Importing namespaces, instantiating objects, calling functions

Classes under this space are only available if the namespace of the DLL is imported. Therefore, the first step after referencing the DLL is to import the namespace, the second step is to instantiate the class object, and finally the class object is used to invoke its member function. The code shown below is a call to the initialization function in the encapsulated DMC3000.dll.

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using nsLTDMC;//(1) Introducing namespaces using Nsdmc3000;namespace dalsaconfig{public  partial class Form1:form  {    //(2) Declaring class objects    DMC3000 m_ f1dmc3000;    Public Form1 ()    {      //(3) Instantiate class object      m_f1dmc3000 = new DMC3000 ();      InitializeComponent ();      (4) Call the function in the DLL      bool Biniresult = M_f1dmc3000.init ();      if (true = = Biniresult)      {        MessageBox.Show ("Init OK");      }      else      {        MessageBox.Show ("Init failed!");      }    }}}  

Steps to debug a DLL function

The first 2 basic steps are how to invoke the functions in the DLL, and this step is the step to debug your own encapsulated DLL.

Add an existing project

Adding an existing project means loading the encapsulated DLL project into the main program so that you can step into the DLL-called function when debugging.

Setting dependencies

A dependency is a project that specifies that the main program is a startup project and that the DLL program is dependent.

The above is the implementation of C # load DLL and call its functions text-to-detail content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.