📄 commonfunctions.hpp
字号:
//
// 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.
//
#pragma once
#ifndef __COMMONFUNCTIONS_HPP__
#define __COMMONFUNCTIONS_HPP__
#include <windows.h>
#include <atlbase.h> //for CComPtr declaration
#include <winuserm.h>
#include "rtccore.h"
#include <atlwin.h>
#include "auto_xxx.hxx"
class VoIPApp_t;
VoIPApp_t *GetApp();
interface IRTCClient;
IRTCClient* GetRTCClientPointer();
#define ARRAYSIZE(a) sizeof(a)/(sizeof((a)[0]))
#define NULL_TERMINATE_ARRAY(a) (a)[ARRAYSIZE(a)-1] = 0
//*** CASSERT -- compile-time assert
#ifndef CASSERT
#define CASSERT(e) extern int dummary_array[(e)]
#endif
//Macro's describing special characters...
#define URI_DOMAIN_SEPARATOR L'@'
//Prevent naming collisions
class PhoneAppUtilities_t
{
public:
/*------------------------------------------------------------------------------
AreCOMPointersEqual
Utility function that determines if 2 COM pointers are equal by comparing
their underlying IUnknown pointers
------------------------------------------------------------------------------*/
template <class T>
static bool AreCOMPointersEqual(
__in_opt T* pT,
__in_opt T* pOtherT
)
{
//validate input
if (! pT || ! pOtherT)
{
return false;
}
//get the IUnknown pointers for both input pointers - then compare
CComPtr<IUnknown> pUnkT;
if ( FAILED(pT->QueryInterface(IID_IUnknown, reinterpret_cast<VOID**>(&pUnkT))) )
{
ASSERT(FALSE);
return false;
}
CComPtr<IUnknown> pUnkOtherT;
if ( FAILED(pOtherT->QueryInterface(IID_IUnknown, reinterpret_cast<VOID**>(&pUnkOtherT))) )
{
ASSERT(FALSE);
return false;
}
return (static_cast<IUnknown*>(pUnkT) == static_cast<IUnknown*>(pUnkOtherT));
}
/*------------------------------------------------------------------------------
NullOutCOMPtr
Helper function that sets a valid (previously defined in a CComPtr) to
NULL - without calling release - to be used when the DLL is being unloaded.
------------------------------------------------------------------------------*/
template <class T>
static inline void NullOutCOMPtr(
__deref_out_opt T** ppT
)
{
ASSERT(ppT);
*ppT = NULL;
}
/*------------------------------------------------------------------------------
DoesFileExist
Helper function that determines if a file exists or not
------------------------------------------------------------------------------*/
static inline bool DoesFileExist(
__in const WCHAR* pFileName
)
{
ASSERT(pFileName != NULL && pFileName[0]);
return (GetFileAttributes(pFileName) != (DWORD)(-1));
}
/*------------------------------------------------------------------------------
IsDigit
Helper function that determines if a character is decimal-digit
------------------------------------------------------------------------------*/
static inline bool IsDigit(
WCHAR Character
)
{
return (Character >= L'0' && Character <= L'9');
}
/*------------------------------------------------------------------------------
IsWhiteSpace
Helper function that determines if a character is white space
As an optimization only match against space and tab characters. We do not
expect other white space characters within the user dial sttring.
------------------------------------------------------------------------------*/
static inline bool IsWhiteSpace(
WCHAR Character
)
{
//return (0 != iswspace(Character));
return ((Character == L' ') || (Character == L'\t'));
}
/*------------------------------------------------------------------------------
TranslateVKeyToDTMFCode
Helper function that translates a virtual key into the appropiate
rtc DMTF code
------------------------------------------------------------------------------*/
static HRESULT TranslateVKeyToDTMFCode(
UINT vkKeyCode,
__in RTC_DTMF* pDTMFCode
)
{
if (!pDTMFCode)
{
return E_POINTER;
}
HRESULT hr = S_OK;
switch (vkKeyCode)
{
case VK_T0:
case VK_T1:
case VK_T2:
case VK_T3:
case VK_T4:
case VK_T5:
case VK_T6:
case VK_T7:
case VK_T8:
case VK_T9:
*pDTMFCode = static_cast<RTC_DTMF>(static_cast<int>(RTC_DTMF_0) + (vkKeyCode - VK_T0));
break;
case VK_TSTAR:
*pDTMFCode = RTC_DTMF_STAR;
break;
case VK_TPOUND:
*pDTMFCode = RTC_DTMF_POUND;
break;
case L'A':
case L'B':
case L'C':
case L'D':
// VK_A through VK_Z are the same as ASCII 'A' through 'Z' (0x41 - 0x5A)
*pDTMFCode = static_cast<RTC_DTMF>(static_cast<int>(RTC_DTMF_A) + (vkKeyCode - L'A'));
break;
default:
*pDTMFCode = RTC_DTMF_0;
hr = E_FAIL;
}
return hr;
}
static inline int InvStrCmpNI(
__in const WCHAR* pString1,
__in const WCHAR* pString2,
size_t NumberOfChars
)
{
size_t MaxChars = ((size_t)(NumberOfChars) < STRSAFE_MAX_CCH ? (size_t)(NumberOfChars) : STRSAFE_MAX_CCH);
size_t String1Length, String2Length;
HRESULT hr = S_OK;
hr = StringCchLength((pString1), MaxChars, &String1Length);
if (FAILED(hr))
{
String1Length = MaxChars;
}
hr = StringCchLength((pString2), MaxChars, &String2Length);
if (FAILED(hr))
{
String2Length = MaxChars;
}
return (CompareString(
MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT),
NORM_IGNORECASE,
pString1,
static_cast<int>(String1Length),
pString2,
static_cast<int>(String2Length)
)- CSTR_EQUAL);
}
};
#endif /* __COMMONFUNCTIONS_HPP__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -