Attribute VB_Name = "modGetODEPath"
Option Explicit

' Declare statements for registry functions.

Private Declare Function RegCreateKeyEx _
    Lib "advapi32.dll" Alias "RegCreateKeyExA" _
    (ByVal hKey As Long, ByVal lpSubKey As String, _
    ByVal ulReserved As Long, ByVal lpClass As String, _
    ByVal dwOptions As Long, ByVal samDesired As Long, _
    lpSecurityAttributes As Any, _
    phkResult As Long, lpdwDisposition As Long) As Long

Private Declare Function RegOpenKeyEx _
    Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    (ByVal hKey As Long, ByVal lpSubKey As String, _
    ByVal ulOptions As Long, ByVal samDesired As Long, _
    phkResult As Long) As Long

Private Declare Function RegSetValueEx _
    Lib "advapi32.dll" Alias "RegSetValueExA" _
    (ByVal hKey As Long, ByVal lpValueName As String, _
    ByVal dwReserved As Long, ByVal dwType As Long, _
    ByVal lpData As Any, ByVal cbData As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" _
   (ByVal hKey As Long) As Long

Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
    Alias "RegQueryValueExA" (ByVal hKey As Long, _
    ByVal lpValueName As String, ByVal lpReserved As Long, _
    lpType As Long, ByVal lpData As String, lpcbData As Long) As Long

' Constants for value types.
Private Const REG_SZ As Long = 1
Private Const REG_DWORD As Long = 4

' Constants for root keys.
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003

Private Const REG_OPTION_NON_VOLATILE = 0
Private Const KEY_ALL_ACCESS = &H3F

Function GetODEPath() As String
    ' Retrieves from the registry the path to the user's
    ' Office 2000 Developer installation.

    Dim hKey        As Long
    Dim lngReturn   As Long
    Dim lngType     As Long
    Dim lngLen      As Long
    Dim strBuffer   As String
    Dim strODEPath  As String
    
    Const REG_ODE_PATH_KEY As String = "Software\Microsoft\ODE\9.0\"
    Const REG_ODE_PATH As String = "ODEToolsPath"

    ' Open key specifying path to ODETools directory.
    lngReturn = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
        REG_ODE_PATH_KEY, 0, KEY_ALL_ACCESS, hKey)
    
    ' RegOpenKeyEx returns 0 on success.
    If lngReturn = 0 Then
        ' Create buffer for result.
        strBuffer = String$(255, vbNullChar)
        lngLen = Len(strBuffer)
        ' Return value into buffer.
        lngReturn = RegQueryValueEx(hKey, REG_ODE_PATH, 0, _
            lngType, strBuffer, lngLen)
        ' RegQueryValueEx returns 0 on success.
        If lngReturn = 0 Then
            strODEPath = Left(strBuffer, _
                InStr(strBuffer, vbNullChar) - 1)
            ' Return path to ODETools.
            GetODEPath = strODEPath
        Else
            ' Return empty string if call failed.
            GetODEPath = ""
        End If
    Else
        ' Return empty string if call failed.
        GetODEPath = ""
    End If
End Function

