调试VB6应用程序时如何设置工作目录?
时间:2020-03-06 14:56:19 来源:igfitidea点击:
我正在调试VB6可执行文件。可执行文件在运行时会从其当前目录加载dll和文件。在调试器中运行时,当前目录似乎是VB6的目录。
如何设置VB6的工作目录?
解决方案
这会工作吗?
'Declaration Private Declare Function SetCurrentDirectory Lib "kernel32" _ Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long 'syntax to set current dir SetCurrentDirectory App.Path
对于这件事,它似乎不是一个"开箱即用"的解决方案。
摘自旧乔尔软件论坛
Anyways.. to put this topic to rest.. the following was my VB6 solution: I define 2 symbols in my VB project "MPDEBUG" and "MPRELEASE" and call the following function as the first operation in my apps entry point function.
Public Sub ChangeDirToApp() #If MPDEBUG = 0 And MPRELEASE = 1 Then ' assume that in final release builds the current dir will be the location ' of where the .exe was installed; paths are relative to the install dir ChDrive App.path ChDir App.path #Else ' in all debug/IDE related builds, we need to switch to the "bin" dir ChDrive App.path ChDir App.path & BackSlash(App.path) & "..\bin" #End If End Sub
我发现可以使用的解决方案使用一个" Sub Main",并检查程序是否在IDE中运行。
Dim gISIDE as Boolean Sub Main() If IsIDE Then ChDrive App.Path ChDir App.Path End If ' The rest of the code goes here... End Sub Public Function IsIDE() As Boolean ' IsIDE = False 'This line is only executed if running in the IDE and then returns True Debug.Assert CheckIDE If gISIDE Then IsIDE = True End If End Function Private Function CheckIDE() As Boolean ' this is a helper function for Public Function IsIDE() gISIDE = True 'set global flag CheckIDE = True End Function
仅当使用File-Open打开项目时,"当前目录似乎是VB6的目录"。
在关闭IDE的情况下,双击.vbp文件将其打开。
可以在快捷方式的属性中更改任何程序(包括vb6)的当前目录。我已经将其更改为源树的根,这使得使用File-Open的速度更快。