在VB中通过相对路径引用标准DLL

来源:互联网 发布:金魔方软件下载 编辑:程序博客网 时间:2024/06/06 03:53

 很长时间以来,都认为只能通过绝对路径引用标准DLL中的函数。其实,你也可以用相对路径。很简单的,现在就尝试一下吧。

   1)绝对路径方法

   比如你的DLL文件位于c:/testDLL/debug/testDLL.dll

   一般来说,你需要在VB中作如下声明

Declare Sub mytest Lib "c:/testDLL/dubug/testDLL.dll" (ByVal x As Long) 


   另外的一个变通方法是把testDLL.dll放在windows的系统目录下,这样,你就可以直接引用文件名了。不过,需要把一个文件放到windows系统目录下,很是不爽!

   2)相对路径方法

   看看我们如何用相对路径,假设你的DLL文件位于c:/testDLL/debug/testDLL.dll,你的VB程序位于目录c:/testDLL/vbClient
你可以在VB程序中作如下声明:

Declare Sub mytest Lib "../dubug/testDLL.dll" (ByVal x As Long) 


   如果直接运行你的VB程序,系统会提示错误:找不到../dubug/testDLL.dll.

   为了使上面的声明其作用,先暂时关闭你的VB工程。然后用一个文本编辑器(notepad,editplus,etc)打开工程文件(就是那个后缀是vbp的家伙),通常vbp文件由几个部分组成,比如我的vbp有两部分:

Type=Exe
Reference=*/G{00020430-0000-0000-C000-000000000046}#2.0#0#../../../../WINDOWS/System32/stdole2.tlb#OLE Automation
Form=Form1.frm
Module=Module1; Module1.bas
Startup="Form1"
ExeName32="Project1.exe"
Command32=""
Name="Project1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="American Standard"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1 
 


   你要做的就是在第一部分MaxNumberofThreads=1后添加一行DebugStartupOption=0。这样,vbp文件就会像下面这样:

......(前面的都一样,故省略)

ThreadPerObject=0
MaxNumberOfThreads=1
DebugStartupOption=0

[MS Transaction Server]
AutoRefresh=1 
 


   OK.That''s all!!重新用VB开发环境打开你的工程然后运行。奇迹发生了吧!

 

原创粉丝点击