// contructor for CWAB object
//
// pszFileName - FileName of WAB file to open
//          if no file name is specified, opens the default
//
CWAB::CWAB(nsILocalFile *file)
{
    // Here we load the WAB Object and initialize it
    m_pUniBuff = NULL;
  m_uniBuffLen = 0;

  m_bInitialized = PR_FALSE;
  m_lpAdrBook = NULL;
  m_lpWABObject = NULL;
  m_hinstWAB = NULL;

    {
        TCHAR  szWABDllPath[MAX_PATH];
        DWORD  dwType = 0;
        ULONG  cbData = sizeof(szWABDllPath);
        HKEY hKey = NULL;

        *szWABDllPath = '\0';

        // First we look under the default WAB DLL path location in the
        // Registry.
        // WAB_DLL_PATH_KEY is defined in wabapi.h
        //
        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey))
            RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);

        if(hKey) RegCloseKey(hKey);

        // if the Registry came up blank, we do a loadlibrary on the wab32.dll
        // WAB_DLL_NAME is defined in wabapi.h
        //
        m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
    }

    if(m_hinstWAB)
    {
        // if we loaded the dll, get the entry point
        //
        m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");

        if(m_lpfnWABOpen)
        {
          char    fName[2] = {0, 0};
            HRESULT hr = E_FAIL;
            WAB_PARAM wp = {0};
            wp.cbSize = sizeof(WAB_PARAM);
            if (file != nsnull) {
                nsCString path;
              file->GetNativePath(path);
              wp.szFileName = (LPTSTR) ToNewCString(path);
            }
            else
              wp.szFileName = (LPTSTR) fName;

            // if we choose not to pass in a WAB_PARAM object,
            // the default WAB file will be opened up
            //
            hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0);

            if(!hr)
                m_bInitialized = TRUE;

        }
    }

}
Beispiel #2
0
// contructor for CWAB object
//
// pszFileName - FileName of WAB file to open
//          if no file name is specified, opens the default
//
CWAB::CWAB(nsILocalFile *file)
{
    // Here we load the WAB Object and initialize it
    m_pUniBuff = NULL;
  m_uniBuffLen = 0;

  m_bInitialized = PR_FALSE;
  m_lpAdrBook = NULL;
  m_lpWABObject = NULL;
  m_hinstWAB = NULL;

    {
        TCHAR  szWABDllPath[MAX_PATH];
        DWORD  dwType = 0;
        ULONG  cbData = sizeof(szWABDllPath);
        HKEY hKey = NULL;

        *szWABDllPath = '\0';

        // First we look under the default WAB DLL path location in the
        // Registry.
        // WAB_DLL_PATH_KEY is defined in wabapi.h
        //
        if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &hKey)) {
            RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szWABDllPath, &cbData);
            if (dwType == REG_EXPAND_SZ) {
                // Expand the environment variables
                DWORD bufferSize = ExpandEnvironmentStrings(szWABDllPath, NULL, 0);
                if (bufferSize && bufferSize < MAX_PATH) {
                    TCHAR tmp[MAX_PATH];
                    ExpandEnvironmentStrings(szWABDllPath, tmp, bufferSize);
                    _tcscpy(szWABDllPath, tmp);
                }
                else {
                    // This is an error condition. Nothing else is initialized yet, so simply return.
                    return;
                }

            }
        }
        else {
            if (GetSystemDirectory(szWABDllPath, MAX_PATH)) {
                _tcsncat(szWABDllPath, WAB_DLL_NAME,
                         NS_MIN(_tcslen(WAB_DLL_NAME), MAX_PATH - _tcslen(szWABDllPath) - 1));
            }
            else {
                // Yet another error condition.
                return;
            }
        }

        if(hKey) RegCloseKey(hKey);

        // if the Registry came up blank, we do a loadlibrary on the wab32.dll
        // WAB_DLL_NAME is defined in wabapi.h
        //
        m_hinstWAB = LoadLibrary( (lstrlen(szWABDllPath)) ? szWABDllPath : WAB_DLL_NAME );
    }

    if(m_hinstWAB)
    {
        // if we loaded the dll, get the entry point
        //
        m_lpfnWABOpen = (LPWABOPEN) GetProcAddress(m_hinstWAB, "WABOpen");

        if(m_lpfnWABOpen)
        {
          char    fName[2] = {0, 0};
            HRESULT hr = E_FAIL;
            WAB_PARAM wp = {0};
            wp.cbSize = sizeof(WAB_PARAM);
            if (file != nsnull) {
                nsCString path;
              file->GetNativePath(path);
              wp.szFileName = (LPTSTR) ToNewCString(path);
            }
            else
              wp.szFileName = (LPTSTR) fName;

            // if we choose not to pass in a WAB_PARAM object,
            // the default WAB file will be opened up
            //
            hr = m_lpfnWABOpen(&m_lpAdrBook,&m_lpWABObject,&wp,0);

            if(!hr)
                m_bInitialized = TRUE;

        }
    }

}