回 帖 发 新 帖 刷新版面

主题:C#中动态引用DLL问题

using System;
using System.Collections.Generic;
using System.Text;
namespace my
{
    public class mytoall
    {
        public static int getall(int a ,int b)
        {
            return a + b;
        }
    }
}

编译成DLL文件(my.dll),新建了个test的Application
把my.dll复制到debug下面,为什么这样引用会有错误?
(不要右键-添加引用,这样谁都会)
namespace test
{
  

    public partial class Form1 : Form
    {  
      [DllImport("my.dll")]
     public static extern int getall(int a,int b);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {  
        
            MessageBox.Show(getall(521,365).ToString());
        }
    }
}

回复列表 (共1个回复)

沙发

dllimport只适用于非托管dll,此外,这是前期绑定,并非动态绑定

动态绑定.net dll,需要利用AppDomain

我来回复

您尚未登录,请登录后再回复。点此登录或注册