想做一个训练软件,实现的功能是给游戏提供一个接口,训练软件就可以外加载游戏并且可以控制游戏,现在想把游戏做成dll文件(如dodger.dll),公共接口Myinterface也做成dll文件(Myinterface.dll),那应该怎么在程序中通过接口将游戏加载进去呢?并显示游戏窗口??
解决方案 »
- vs2008关闭解决方案时卡死
- 在自定义日志名称中,只有前八个字符才有效
- DataGrid等一些数据集在更新数据时是如何保证修改数据的唯一性的
- 谁能提供C#编写HTTP代理服务器的原码呢.课程设计要用到.时间紧迫........
- SQL SERVER2000的数据表的表字段用中文命名好不好
- this.page.RegisterStartupScript中的script为什么不发生作用?????????????
- 怎样在C#的Windows应用程序中实现倒计时?
- 一个动态创建Button控件的问题,UP者也有分!
- 请教:如何用c#实现从一个网页自动获取一部分数据。
- SQL循环更新数据库
- 代码如何实现 控制面板中添加Windows 凭据
- System.Windows.Forms里的TIMER
然后项目添加引用此dll/
C# 里面调用里面的方法之类的 实现加载。显示窗口。
如果DLL是C++写的,用DllImport方式加载;
private MyInterFace.InterFace iObj;//定义一个MyInterFace实例
Assembly assembly = Assembly.LoadFrom(str + ".dll");
Type type = assembly.GetType(str + ".Form1");
try
{
object obj = Activator.CreateInstance(type, new Object[]{300,400} );
this.iObj = (MyInterFace.InterFace)obj;
//iObj.InitializeGraphics();
}
catch (System.Reflection.TargetInvocationException ex)
{
throw ex.InnerException;
}
//反馈刺激中的函数——初始化引擎;
iObj.InitializeGraphics();
iObj.myShow();
在没对所加载的dll文件进行注册时,运行到object obj = Activator.CreateInstance(type, new Object[]{300,400}的时候,程序就卡死在那了,但是也没给出错误提示,注册dll文件之后还是出现相同的情况,就不知道到底是哪出问题了
dll文件都是用C#编写的,也加入引用了,但还是运行到object obj = Activator.CreateInstance(type, new Object[]{300,400}这个地方程序就不往下运行了
private void startGameProcess()
{
this.m_GameThread = new Thread(new ThreadStart(this.gameStart));
this.m_GameThread.Start();
}
private GameInterFace my_GameIF; /// <summary>
/// 游戏调用的函数
/// 关于游戏的调用,这里采用的方法是,线程启动一个窗口,窗口通过调用接口,
/// 实现对dll的动态加载和调用。
/// 这是由于线程启动Application.Run方法中,Run的对象必须是一个窗口,不能是一个接口;
/// </summary>
private void gameStart()
{
string str = "Classroom"; //加载游戏dll的名称,这里直接输入,事实上,这里需要通过数据库读出;
this.my_GameIF = new GameInterFace();
this.my_GameIF.Start(str, 200, 300); //30,50 dll Form出现的位置x y坐标,这里直接输入事实上,从数据库中读出;
Application.Run(this.my_GameIF);
}
public void Start(string str, int x, int y)
{
Assembly assembly = Assembly.LoadFrom(str + ".dll");
Type type = assembly.GetType(str + ".Form1");
// try
// {
object obj = Activator.CreateInstance(type, new Object[]{x, y}); this.iObj = (MyInterFace.InterFace)obj;
// }
// catch(System.Reflection.TargetInvocationException ex)
// {
// throw ex.InnerException;
// }
//反馈刺激中的函数——初始化引擎;
iObj.InitializeGraphics();
iObj.myShow();
}
在object obj = Activator.CreateInstance(type, new Object[]{x, y})这个报错,错误提示为“未处理的“System.Reflection.TargetInvocationException”类型的异常出现在 mscorlib.dll 中。其他信息: 调用的目标发生了异常。
”找了好久都没有找到原因,
请各位高手帮帮忙