当前位置:编程学习 > C#/ASP.NET >>

C#动态调用委托的DLL

被调用的TestDll.dll文件主要代码:

using System;

using System.Collections.Generic;

using System.Text;

namespace TestDll

{

    public class TestDll

    {

        public string HandleStr(string str)

        {

            return "["+str + "]";

        }

    }

}

调用TestDll.dll的HandleStr方法的代码:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Reflection;

 

namespace DynamicInvokeDll

{

    public partial class FrmMain : Form

    {

        public FrmMain()

        {

            InitializeComponent();

        }

 

        private void FrmMain_Load(object sender, EventArgs e)

        {

            object[] obj = new object[1];

            obj[0] = "DllInvoke";

            object o2 = DllInvoke("TestDll.dll", "TestDll", "TestDll", "HandleStr", obj);

            MessageBox.Show(o2.ToString());

        }

 

        /// <summary>

        /// 动态调用DLL

        /// </summary>

        /// <param name="DllFileName">dll名称</param>

        /// <param name="NameSpace">命名空间</param>

&

补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,