top
Loading...
在VB中通過相對路徑引用標準DLL
很長時間以來,都認為只能通過絕對路徑引用標準DLL中的函數。其實,你也可以用相對路徑。很簡單的,現在就嘗試一下吧。

1)絕對路徑方法

比如你的DLL文件位于c:estDLLdebugestDLL.dll

一般來說,你需要在VB中作如下聲明

Declare Sub mytest Lib "c:estDLLdubugestDLL.dll" (ByVal x As Long)

另外的一個變通方法是把testDLL.dll放在windows的系統目錄下,這樣,你就可以直接引用文件名了。不過,需要把一個文件放到windows系統目錄下,很是不爽!

2)相對路徑方法

看看我們如何用相對路徑,假設你的DLL文件位于c:estDLLdebugestDLL.dll,你的VB程序位于目錄c:estDLLvbClient
你可以在VB程序中作如下聲明:

Declare Sub mytest Lib "http://www.zhujiangroad.com/dubug/testDLL.dll" (ByVal x As Long)

如果直接運行你的VB程序,系統會提示錯誤:找不到http://www.zhujiangroad.com/dubug/testDLL.dll.

為了使上面的聲明其作用,先暫時關閉你的VB工程。然后用一個文本編輯器(notepad,editplus,etc)打開工程文件(就是那個后綴是vbp的家伙),通常vbp文件由幾個部分組成,比如我的vbp有兩部分:

Type=Exe
Reference=*G{00020430-0000-0000-C000-000000000046}#2.0#0#........WINDOWSSystem32stdole2.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開發環境打開你的工程然后運行。奇跡發生了吧!
作者:http://www.zhujiangroad.com
來源:http://www.zhujiangroad.com
北斗有巢氏 有巢氏北斗