系统C盘下的common files下有个abc.dll,里有pic的类,该类下有getwid(参数) gethei(参数)等函数。(这是通过对像浏览器看出来的)。想引用它,我用了两种办法:
一、在设计界面下,从工程---引用,定位到该abc.dll文件,加以引用。在窗体前声明部分作了声明
dim t as abclib(这个是添加后自动出现的)
在窗体的命令按钮的点击事件中加代码:
set tt=new abclib
ss=tt.getwid(参数)
运行时,总提示缺少用户自定义类型,停止在dim t as abclib这里。二、用纯DLL的调用方法;
Private Declare Function wantget Lib "C:\Common Files\abc.dll" Alias "Getwid" (ByVal bcanshu As interger) As String
下面用t=wantget(canshu)调用,结果总报C:\Common Files\abc.dll文件找不到,53错误。奇怪!请高手帮助诊断!
一、在设计界面下,从工程---引用,定位到该abc.dll文件,加以引用。在窗体前声明部分作了声明
dim t as abclib(这个是添加后自动出现的)
在窗体的命令按钮的点击事件中加代码:
set tt=new abclib
ss=tt.getwid(参数)
运行时,总提示缺少用户自定义类型,停止在dim t as abclib这里。二、用纯DLL的调用方法;
Private Declare Function wantget Lib "C:\Common Files\abc.dll" Alias "Getwid" (ByVal bcanshu As interger) As String
下面用t=wantget(canshu)调用,结果总报C:\Common Files\abc.dll文件找不到,53错误。奇怪!请高手帮助诊断!
Dim t As KSENGINELib.Dictionary
不过 GetPhonetic() 的参数的定义不符合标准 COM 定义,不能被调用。二、如果可以通过对象浏览器看到 wantget,那么应该用引用的方式而不是 Declare 的方式调用。
通过引用后的确能看到dll中的类和函数。您认为: GetPhonetic() 的参数的定义不符合标准 COM 定义,不能被调用。——我用Dim t As KSENGINELib.Dictionary 这样的方式也试过,GetPhonetic() 中的参数,按对像浏览器是看到的,显示为string类型,传递的是text1.text,也是这种类型,有哪里不合com定义呢?
请进一步赐教!
private t as abc.pic
set t=new pic我这个机器每次引用DLL的时候都得重新编译一下Dll才可以,你把它编译了再试试吧
我可以用第一种方法实现对系统中原有的那个文件(安装词霸时安装的那个)引用并建立对象,但楼主的的确不行。而且楼主的那个引用后,GetPhonetic只是一个SUb , 根本没有返回值,即使成功,楼主的代码也有问题。
第二种方法恐怕不行,正如2楼所说。
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: KSEngine.dll[
uuid(4A548BD4-98D6-4FCD-9A3C-79894A606FD1),
version(1.0),
helpstring("KSEngine 1.0 Type Library")
]
library KSENGINELib
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb"); // Forward declare all types defined in this typelib
interface IDictionary; [
uuid(69B940A9-FA3A-4F8F-B64E-98BBFA7B8E99),
helpstring("Dictionary Class")
]
coclass Dictionary {
[default] interface IDictionary;
}; [
odl,
uuid(71FA90AF-3ECB-496D-A89D-7EB23C8A0D98),
helpstring("IDictionary Interface"),
dual,
oleautomation
]
interface IDictionary : IDispatch {
[id(0x00000001), propget, helpstring("property SrcLanguageId")]
HRESULT SrcLanguageId([out, retval] long* pVal);
[id(0x00000001), propput, helpstring("property SrcLanguageId")]
HRESULT SrcLanguageId([in] long pVal);
[id(0x00000002), propget, helpstring("property DestLanguageId")]
HRESULT DestLanguageId([out, retval] long* pVal);
[id(0x00000002), propput, helpstring("property DestLanguageId")]
HRESULT DestLanguageId([in] long pVal);
[id(0x00000003), helpstring("method Lookup")]
HRESULT Lookup(
BSTR bstrWord,
long lFlag);
[id(0x00000004), helpstring("method GetTitle")]
HRESULT GetTitle(BSTR* bstrTitle);
[id(0x00000005), helpstring("method GetExplain")]
HRESULT GetExplain(BSTR* bstrExplain);
[id(0x00000006), helpstring("method GetPhonetic")]
HRESULT GetPhonetic(BSTR* bstrPhonetic);
[id(0x00000007), helpstring("method Open")]
HRESULT Open(BSTR bstrPath);
[id(0x00000008), helpstring("method Close")]
HRESULT Close();
};
};
其中 GetPhonetic 的参数根本没有 [in|out] 限定,COM 调用(或者说 VB 编译)时无法决定参数该如何出栈/入栈。
to songyaowu:谢谢您!您说:“我可以用第一种方法实现对系统中原有的那个文件(安装词霸时安装的那个)引用并建立对象,但楼主的的确不行。”能把您的代码给我参考一下吗?我上面的代码问题在哪里?谢谢!
Dim t As KSENGINELib.Dictionary
Set t = New KSENGINELib.Dictionary
t.Open "C:\Program Files\...\PWPECDN.DIC"
Debug.Print t.SrcLanguageId
Debug.Print t.DestLanguageId
Set t = New KSEngineLib.Dictionary
Dim tt As String
t.Open ("PWQCE.DIC")
Dim t1 As String: t1 = Text1.Text: Dim t2 As Long
tt = t.Lookup(t1, t2)
Text2.Text = tt请高手们指正!
Private Sub Command1_Click()
Dim t As KSEngineLib.Dictionary
Set t = New KSEngineLib.Dictionary t.Open "F:\Program Files\Kingsoft\PowerWord Lite\plugin\CBDict08\dicts\PWQEC.DIC"
t.Lookup "look", 0
Debug.Print t.GetExplain
Set t = Nothing
End Sub
运行结果: vt. & vi.看, 瞧呵呵,这用的是谷歌金山词霸的dll和字典,成功!至于楼主发来的dll,我仍然坚持上次的观点,可能是许可证的问题。不知楼主搞了这个东西后谷歌金山词霸是不是要考虑这个dll的许可证和字典的加密了。呵呵...
KSEngineLib.Dictionary 的成员
method Lookup我调用lookup时,后一个参数传的1,好像此前看什么受了影响当时就写了1,因为没有说明,就瞎传了个1。
按songyaowu高手的传递0,正常,谢谢!
再次请教,在这种看不见参数要求的情况下,传0传1什么的,有什么经验?
nef = App.Path & "\PWQEC.DIC"
'nef = "D:\Program Files\Kingsoft\PowerWord Lite\plugin\CBDict08\dicts\PWQEC.DIC"
t.Open nef
't.Open "D:\Program Files\Kingsoft\PowerWord Lite\plugin\CBDict08\dicts\PWQEC.DIC"
我将系统中的字典文件放到当前程序下,用相对路径的方式来打开(如上),就会出错,请问这是为何?