Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set working directory when debugging VB6 app?

Tags:

vb6

I am debugging a VB6 executable. The executable loads dlls and files from it's current directory, when running. When run in debugger, the current directory seems to be VB6's dir.

How do I set working directory for VB6?

like image 683
jm. Avatar asked Sep 30 '08 18:09

jm.


4 Answers

Solution that I have found that works uses a Sub Main, and checks if the program is running in the 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
like image 106
Kris Erickson Avatar answered Sep 21 '22 08:09

Kris Erickson


It doesn't seems to be a "out of the box" solution for this thing.

Taken from The Old Joel On Software Forums

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
like image 29
Pascal Paradis Avatar answered Sep 18 '22 08:09

Pascal Paradis


"The current directory seems to be VB6's dir" only when you open a project using File-Open.

Open it by double clicking the .vbp file while having the IDE closed.

like image 8
GSerg Avatar answered Sep 18 '22 08:09

GSerg


Will this work?

'Declaration
Private Declare Function SetCurrentDirectory Lib "kernel32" _
Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long

'syntax to set current dir
SetCurrentDirectory App.Path
like image 2
Gulzar Nazim Avatar answered Sep 18 '22 08:09

Gulzar Nazim