Call function from DLL?

后端 未结 5 760
灰色年华
灰色年华 2020-12-14 06:36

I\'m new to C# and I\'m trying to learn to usage of DLLs. I\'m trying to wrap my objects in a DLL, and then use it in my program.

public class Foo   // its in         


        
5条回答
  •  时光说笑
    2020-12-14 07:20

    Depends on what type of DLL. Is this built in .NET ? if it is unmanaged code then here is an example otherwise the Answer from Rob will work.

    Unmanaged C++ dll example:

    using System;
    using System.Runtime.InteropServices;
    

    You may need to use DllImport

    [DllImport(@"C:\Cadence\SPB_16.5\tools\bin\mpsc.dll")]
    static extern void mpscExit();
    

    or

    [DllImport("user32.dll", CharSet = CharSet.Unicode)]
    public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);
    

    Then each of those are called like this:

    // a specific DLL method/function call
    mpscExit();
    // user32.dll is Microsoft, path not needed
    MessageBox(new IntPtr(0), "Test", "Test Dialog", 0);  
    

提交回复
热议问题