C#调用dll!!!!!!!!!!!!!
想做一个训练软件,实现的功能是给游戏提供一个接口,训练软件就可以外加载游戏并且可以控制游戏,现在想把游戏做成dll文件(如dodger.dll),公共接口Myinterface也做成dll文件(Myinterface.dll),那应该怎么在程序中通过接口将游戏加载进去呢?并显示游戏窗口??
//Interface.cs namespace Game { public interface MyInterface { void Close(); void DoXX(); void ShowInfo(string info); } } //FormGame.cs using System.Windows.Forms; namespace Game { public partial class FormGame : Form, MyInterface { #region 构造函数 public FormGame() { InitializeComponent(); } #endregion #region 接口实现 public void DoXX() { } public void ShowInfo(string info) { TbInfo.AppendText(string.Concat(info, "\r\n")); } #endregion } } //Controller.cs using Game; namespace Tranning.Controller { public class Controller { #region 全局字段 private MyInterface _myInterface; #endregion #region 公共方法 public void CloseGame() { _myInterface.Close(); } public void OpenGame() { var formGame = new FormGame(); formGame.Show(); _myInterface = formGame; } public void ShowMessage(string s) { _myInterface.ShowInfo(s); } #endregion } } //FormMain.cs using System; using System.Windows.Forms; using Tranning.Controller; namespace DllCallDllForm { public partial class FormMain : Form { #region 只读全局字段 private readonly Controller _controller; #endregion #region 构造函数 public FormMain() { InitializeComponent(); _controller = new Controller(); } #endregion #region 构造函数 private void ButCloseGame_Click(object sender, EventArgs e) { _controller.CloseGame(); } private void ButOpenGame_Click(object sender, EventArgs e) { _controller.OpenGame(); } private void ButSendInfo_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(TbMessage.Text)) return; _controller.ShowMessage(TbMessage.Text); } #endregion } }