用C#生成了DLL文件,C#代码如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LeonQtp
{
public class Qtp_Msg
{
public static int MessageBoxL(string Msg, string Caption)
{
MessageBox.Show(Msg, Caption, MessageBoxButtons.OKCancel);
return 0;
}
}
}###############################################################################################
上述代码生成的DLL,可用C#调用成功
但是在QTP中,用下面语句调用失败:
Set CSharp_Msg = DotNetFactory.CreateInstance("LeonQtp.Qtp_Msg","C:\Leon\New\LeonQtp.dll")
Ret = CSharp_Msg.MessageBoxL("Call by DotNetFactory!","by DNF obj")Error如下:
Could not load file or assembly 'file:///C:\Leon\New\LeonQtp.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.大家帮忙看下吧~~~
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LeonQtp
{
public class Qtp_Msg
{
public static int MessageBoxL(string Msg, string Caption)
{
MessageBox.Show(Msg, Caption, MessageBoxButtons.OKCancel);
return 0;
}
}
}###############################################################################################
上述代码生成的DLL,可用C#调用成功
但是在QTP中,用下面语句调用失败:
Set CSharp_Msg = DotNetFactory.CreateInstance("LeonQtp.Qtp_Msg","C:\Leon\New\LeonQtp.dll")
Ret = CSharp_Msg.MessageBoxL("Call by DotNetFactory!","by DNF obj")Error如下:
Could not load file or assembly 'file:///C:\Leon\New\LeonQtp.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.大家帮忙看下吧~~~
我的C#的DLL目前不是用的COM~
是不是和Assembly.Load("foo"); 这种调用差不多,把dll后最去掉试试
Set CSharp_Msg = DotNetFactory.CreateInstance("LeonQtp.Qtp_Msg","C:\Leon\New\LeonQtp")
比如它依赖哪些dll,都要加载
以前用DLL的时候,DLL如果导出的是对象,那么调用的时候很不方便,有语言限制,编译器限制的。
用C写的DLL,如果不用.def的话有编译器限制,因为函数名会因为编译器不同而不同。
用了.def可以解决函数名变掉的问题。但是貌似.def里面只能导出函数,没法导出对象的。
而且,还有语言限制问题,有的语言调用约定不一样,也比较讨厌。但是用了C#的.NET对象,发现DLL调用变简单了貌似VB可以直接调用C#的DLL。。C#也能调用VB的DLL以前看过些COM的技术文档,知道如果凭借COM的技术是可以生成跨语言的DLL的所以就不由的想,.NeT对象封装的对象,是否都是用了COM技术,其实质就是COM对象。今天查了DotNetFactory文档,发现CreateInstance函数返回值是一个COM接口。文档原文如:
Returns a COM interface for a .NET object有没有人用过的,帮忙看看啊~~~
愁死了~~