⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 databaseapi.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "DatabaseAPI.hpp"
#include "VoIPNotify.hpp"
#include <atlbase.h> 
#include "voipstore.h"
#include <auto_xxx.hxx>         
#include "Common.hpp"
#include "CommandAPI.hpp"


const WCHAR c_DefaultDatabaseName[] = L"VoIPDB"; 
const int   c_CallLogDBCapacity     = 100; 

HRESULT
GetDatabaseName(
    BSTR*   pbstrDatabaseName
    )
{
    if (pbstrDatabaseName == NULL)
    {
        return E_INVALIDARG; 
    }

    *pbstrDatabaseName = NULL; 
    
    WCHAR DatabaseName[MAX_PATH] = L""; 
    
    HRESULT hr = RegistryGetString(
                    SN_VOIP_DBNAME_ROOT, 
                    SN_VOIP_DBNAME_PATH, 
                    SN_VOIP_DBNAME_VALUE, 
                    DatabaseName, 
                    _countof(DatabaseName)
                    ); 
    if (FAILED(hr))
    {
        *pbstrDatabaseName = SysAllocString(c_DefaultDatabaseName);         
    }
    else
    {
        *pbstrDatabaseName = SysAllocString(DatabaseName); 
    }
    
    if (*pbstrDatabaseName == NULL)
    {
        return E_OUTOFMEMORY; 
    }

    return S_OK; 
}

EXTERN_C
HRESULT
WINAPI PHInitCallLogDB(
    IVoIPCallLogDB** ppiCallLogDB
    )
{
    if (ppiCallLogDB == NULL)
    {
        return E_INVALIDARG; 
    }

    *ppiCallLogDB = NULL; 
    
    CComPtr<IVoIPCallLogDB> cpCallLogDB; 
    
    HRESULT hr = cpCallLogDB.CoCreateInstance(CLSID_VoIPCallLogDB); 
    if (FAILED(hr))
    {
        return hr; 
    }

    ce::auto_bstr bstrDatabaseName; 

    hr = GetDatabaseName(&bstrDatabaseName); 
    if (FAILED(hr))
    {
        return hr; 
    }
    
    hr = cpCallLogDB->Init(bstrDatabaseName); 
    if (FAILED(hr))
    {
        return hr; 
    }

    hr = cpCallLogDB->put_Capacity(c_CallLogDBCapacity); 
    if (FAILED(hr))
    {
        return hr; 
    }

    *ppiCallLogDB = cpCallLogDB; 
    (*ppiCallLogDB)->AddRef(); 

    return hr; 

}

EXTERN_C
HRESULT
WINAPI PHInitCallerInfoDB(
    IVoIPCallerInfoDB** ppiCallerInfoDB
    )
{
    if (ppiCallerInfoDB == NULL)
    {
        return E_INVALIDARG; 
    }

    *ppiCallerInfoDB = NULL; 

    CComPtr<IVoIPCallerInfoDB> cpCallerInfoDB; 
    
    HRESULT hr = cpCallerInfoDB.CoCreateInstance(CLSID_VoIPCallerInfoDB); 
    if (FAILED(hr))
    {
        return hr; 
    }

    ce::auto_bstr bstrDatabaseName; 
    hr = GetDatabaseName(&bstrDatabaseName); 
    if (FAILED(hr))
    {
        return hr;     
    }

    hr = cpCallerInfoDB->Init(bstrDatabaseName); 
    if (FAILED(hr))
    {
        return hr; 
    }

    *ppiCallerInfoDB = cpCallerInfoDB; 
    (*ppiCallerInfoDB)->AddRef(); 

    return hr; 
}

EXTERN_C
HRESULT
WINAPI
PHAddSpeedDialEntry(
    PH_SPEEDDIAL_ENTRY* pEntry
    )
{
    //verify the input parameter
    if (! pEntry)
    {
        ASSERT(FALSE);
        return E_POINTER;
    }

    //currently the size MUST be sizeof PH_SPEEDDIAL_ENTRY
    if (pEntry->StructSize != sizeof(PH_SPEEDDIAL_ENTRY))
    {
        ASSERT(FALSE);
        return E_INVALIDARG;
    }

    //verify there is a number to send...
    if (! pEntry->pNumber[0])
    {
        return E_INVALIDARG;
    }

    //
    // If the info app is running, send it the copydata
    // else (NOT running) start the app and then send the copydata
    //

    HWND            InfoAppWindow;
    HCURSOR         OldCursor;
    COPYDATASTRUCT  CopyDataStruct;
    
    HRESULT hr           = S_OK;
    
    //is the info app running?
    InfoAppWindow = PHGetAppWindow(phaContactsApp, FALSE);
    if (! InfoAppWindow)
    {       
        //create the info app process - hidden!
        hr = PHLaunchProcess(
            L"PhInfo.exe",
            L"-n",
            NULL
            );
        if (FAILED(hr))
        {
            ASSERT(FALSE);
            return hr;
        }

        //show the wait cursor...
        OldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
        
        //We need to wait for the app to start...
        InfoAppWindow = PHGetAppWindow(phaContactsApp, TRUE);

        //restore the cursor
        SetCursor(OldCursor);

        //is the app running now?
        if (! InfoAppWindow)
        {
            return E_FAIL;
        }        
    }

    //ready to send the data!
    CopyDataStruct.dwData = INFOAPPMSG_ADDTOSPEEDDIAL;
    CopyDataStruct.cbData = pEntry->StructSize;
    CopyDataStruct.lpData = pEntry;

    return (HRESULT)SendMessage(
        InfoAppWindow, 
        WM_COPYDATA, 
        0,
        reinterpret_cast<LPARAM>(&CopyDataStruct)
        );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -