Como definir diretório de trabalho quando a depuração aplicativo VB6?

StackOverflow https://stackoverflow.com/questions/154299

  •  03-07-2019
  •  | 
  •  

Pergunta

Estou a depuração de um executável VB6. As cargas DLLs executáveis ??e arquivos a partir dele do diretório atual, quando em execução. Quando executado no depurador, o diretório atual parece ser dir do VB6.

Como faço para definir o diretório de trabalho para VB6?

Foi útil?

Solução

Ele não parece ser um "fora da caixa" solução para esta coisa.

Os Fóruns Old Joel on Software

De qualquer forma .. para colocar este tema para descansar .. A seguir foi a minha solução VB6: I definir 2 símbolos no meu projeto VB "MPDEBUG" e "MPRELEASE" e chamar a seguinte função como o primeiro operação no meu ponto de entrada aplicativos função.

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

Outras dicas

"O diretório atual parece ser dir do VB6" somente quando você abrir um projeto usando Arquivo-Abrir.

abri-lo clicando duas vezes no arquivo .vbp ao ter o IDE fechada.

solução que eu descobri que obras usa um Sub Main, e verifica se o programa está sendo executado no 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

Será que este trabalho?

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

'syntax to set current dir
SetCurrentDirectory App.Path

O diretório atual para qualquer programa - incluindo vb6 - pode ser alterado nas propriedades do atalho. Eu mudei-o para a raiz da minha árvore de origem, faz usando Arquivo-Abrir mais rápido.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top