在很久很久以前,曾经有一种语言,对于很多人来说是very beautiful,而对于很多人来说是very basic,它就是传说中的vb。现在虽然各类语言风起云涌,但是曾经这个语言也是流行一时。
在很多年前,因为做autoit页面自动化,但是autoit没有很多方面的函数,考虑是否需要做标准dll,如果用vc,怕将来就维护代码是个问题,必须选用更简单的技术,于是用vb,会vb的人比较多。但是vb的ocx dll是COM组件,而非windows标准的dll,故此要寻找方法做出标准的dll,这样就可以提供给各种语言进行调用了。
闲话少叙,开始:
先去下面down下zip包:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=54190&lngWId=1
安装步骤:
0) 解包zip,记录下解包目录;
1) 打开 .\linker\Linker.vbp,编译成MakeDLL.exe,拷贝到vb安装目录(例如:d:\ProgramFiles\Microsoft Visual Studio\VB98)
2) 打开.\addin\MakeDLLAddin.vbp,编译出MakeDLL.dll,MakeDLL.exp,MakeDLL.lib三个文件
3) 拷贝MakeDLL.DLL到vb安装目录,重启vb
4) 拷贝.\dll project\目录到项目模板目录(例如:D:\ProgramFiles\Microsoft Visual Studio\VB98\template\projects)
使用方法:
1) 将项目模板目录下的.\dllproject\拷贝出来,直接进行函数或者过程的修改添加;
试验方法:
1) 先打开目录.\test dll\下的项目,编译成testdll.dll;
2) 再打开目录.\test program\下的项目,打开调用testdll.dll执行。
看看例子是啥样子的:
test dll\modTestDLL.bas:
Attribute VB_Name = “Module1” ”””””””””””””””””””””””” ” DLL PROJECT ?004 DanSoft Australia ” ” Your dlls MUST HAVE a DLLMain and Main ” ” proc, otherwise it won’t compile properly! ” ”””””””””””””””””””””””” Function DLLMain(ByVal A As Long, ByVal B As Long, ByVal c As Long) As Long DLLMain = 1 End Function Sub Main() ‘This is a dummy, so the IDE doesn’t complain ‘there is no Sub Main. End Sub Function addition(ByVal A As Double, ByVal B As Double) As Double addition = A + B End Function Function subtraction(ByVal A As Double, ByVal B As Double) As Double subtraction = A – B End Function |
test dll\TestDLL.def:
LIBRARY TestDLL EXPORTS addition subtraction |
用vb直接写个调用的例子:
test program\frmTest.frm
Private Declare Function subtraction Lib “testDLL.DLL” (ByVal A As Double, ByVal B As Double) As Double Private Declare Function addition Lib “testDLL.DLL” (ByVal A As Double, ByVal B As Double) As Double Private Sub cmdExit_Click() End End Sub Private Sub Form_Load() lblResult(0) = “9.87 + 2.99 = ” & CStr(addition(9.87, 2.99)) lblResult(1) = “10 – 8.43 = ” & CStr(subtraction(10, 8.43)) lblResult(2) = “9999 + 1543 = ” & CStr(addition(9999, 1543)) End Sub |
来看看最后结果:
001.Jpg
好了,怀旧贴大功告成,现在你的VB可以跨越语言,实现互联互通了。
相关下载:
http://download.csdn.net/detail/testingba/5047346