Attribute VB_Name = "Install"
Public Declare Function ShellExecute Lib "shell32.dll" Alias _
    "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
    String, ByVal lpszFile As String, ByVal lpszParams As String, _
    ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    
Private Declare Function GetCurrentDirectory Lib "Kernel32" _
        Alias "GetCurrentDirectoryA" (ByVal nBufferLength As Long, _
        ByVal lpBuffer As String) As Long

Private Declare Function GetSystemDirectory Lib "Kernel32" _
    Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long

Private Declare Function GetTempPath Lib "Kernel32" _
Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function GetWindowsDirectory Lib "Kernel32" _
    Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long
    
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)



Public Sub load_driver()
Dim hwnd As Long
Dim return_value As Long
Dim curDir As String
Dim sysDir As String
Dim tmpDir As String
Dim winDir As String
Dim manip_path As String
Dim manip_len As Integer
curDir = Space(500)
sysDir = Space(500)
tmpDir = Space(500)
winDir = Space(500)
curDir = Left(curDir, GetCurrentDirectory(Len(curDir), curDir))
sysDir = Left(sysDir, GetSystemDirectory(sysDir, Len(sysDir)))
tmpDir = Left(tmpDir, GetTempPath(Len(tmpDir), tmpDir))
winDir = Left(winDir, GetWindowsDirectory(winDir, Len(winDir)))

' Since the installer does not copy windrvr.exe and all that stuff directly to program folder and since
' they are stored in ./source/vb instead of ./program changing app path
manip_path = App.Path
manip_len = Len(manip_path)
manip_len = manip_len - 7
Mid(manip_path, manip_len) = "\Source\"
manip_path = manip_path & "vb"
'MsgBox manip_path
'MsgBox Mid$(App.Path, manip_len)
If (UCase(Mid$(App.Path, manip_len))) = UCase("\Program") Then ' installed using setup

Else
    manip_path = App.Path
End If
'MsgBox manip_path
    If Dir$(manip_path & "\driverinstall.txt") = "" Then
        FileCopy manip_path & "\prvdrv.dll", winDir & "\prvdrv.dll"
        If Dir$(winDir & "\system\vmm32\") <> "" Then
            FileCopy manip_path & "\Windrvr.vxd", winDir & "\system\vmm32\Windrvr.vxd"
        End If
        If Dir$(winDir & "\system32\drivers\") <> "" Then
            FileCopy manip_path & "\Windrvr.sys", winDir & "\system32\drivers\Windrvr.sys"
        End If
        return_value = ShellExecute(hwnd, "open", manip_path & "\wdreg.exe", "install", "C:\", 1)  '<---- 1=Show normal
        Sleep (100)
        F3 = FreeFile
        Open manip_path & "\driverinstall.txt" For Output As F3
        Close #F3
    End If



'MsgBox winDir
    End Sub

Public Sub install_chartdll()
Dim hwnd As Long
Dim return_value As Long
Dim curDir As String
Dim sysDir As String
Dim tmpDir As String
Dim winDir As String
Dim manip_path As String
Dim manip_len As Integer
'Dim manip_path As String
'Dim manip_len As Integer
curDir = Space(500)
sysDir = Space(500)
tmpDir = Space(500)
winDir = Space(500)
curDir = Left(curDir, GetCurrentDirectory(Len(curDir), curDir))
sysDir = Left(sysDir, GetSystemDirectory(sysDir, Len(sysDir)))
tmpDir = Left(tmpDir, GetTempPath(Len(tmpDir), tmpDir))
winDir = Left(winDir, GetWindowsDirectory(winDir, Len(winDir)))
'MsgBox winDir
manip_path = App.Path
manip_len = Len(manip_path)
manip_len = manip_len - 7
Mid(manip_path, manip_len) = "\Source\"
manip_path = manip_path & "vb"
'MsgBox manip_path
If (UCase(Mid$(App.Path, manip_len))) = UCase("\Program") Then ' installed using setup
Else
    manip_path = App.Path
End If
'MsgBox manip_path
If Dir$(manip_path & "\dllinstall.txt") = "" Then
    If Dir$(winDir & "\system\") <> "" Then
        If Dir$(winDir & "\system\msstdfmt.dll") = "" Then
            FileCopy manip_path & "\msstdfmt.dll", winDir & "\system\msstdfmt.dll"
        End If
        return_value = ShellExecute(hwnd, "open", "regsvr32.exe", winDir & "\system\msstdfmt.dll", "C:\", 1) '<---- 1=Show normal
    End If
    If Dir$(winDir & "\system32\") <> "" Then
        If Dir$(winDir & "\system32\msstdfmt.dll") = "" Then
           FileCopy manip_path & "\msstdfmt.dll", winDir & "\system32\msstdfmt.dll"
        End If
        return_value = ShellExecute(hwnd, "open", "regsvr32.exe", winDir & "\system32\msstdfmt.dll", "C:\", 1) '<---- 1=Show normal
    End If
    f = FreeFile
    Open manip_path & "\dllinstall.txt" For Output As f
    Close #f
 End If

'MsgBox return_value
End Sub
