📄 dllmain.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 "Debug.hpp"
#include "Common.hpp"
#include "CommonFunctions.hpp"
#include "VoIPApp.hpp"
#include "ControlDefinitions.h"
#include "rtccore.h"
#include "ProvisionManager.hpp"
#include "PhoneAPI.hpp"
#include "CommandAPI.hpp"
#include "LayoutColor.hpp"
class UIManager_t;
#ifdef DEBUG
//Debug zone information
DBGPARAM dpCurSettings =
{
//Module name
L"PhoneApp",
//Debug zone names
{
L"Error", // 1
L"Constructor/Destructor", // 2 Lowest Hex Digit
L"Memory Allocation", // 4
L"RefCount", // 8
L"Function",
L"RTC Event",
L"DialRules",
L"DialPlan", // 2nd Hex digit
L"", L"", L"", L"", // 3rd Hex digit
L"", L"", L"", L"", // 4th Hex digit
},
//Initial debug zone mask
0x0001
};
#endif
//Global objects
VoIPApp_t* g_pApp = NULL;
//Common HINSTANCE used across the dll
HINSTANCE GlobalData_t::s_ModuleInstance = NULL;
GDICache_t GlobalData_t::s_GDICacheObject;
MemTrackInitialize();
/*------------------------------------------------------------------------------
DllMain
Main entry point into this dll. We only pay attention to process attach/detach
------------------------------------------------------------------------------*/
BOOL
WINAPI DllMain(
HANDLE DllHandle,
DWORD ReasonCode,
LPVOID
)
{
switch(ReasonCode)
{
case DLL_PROCESS_ATTACH:
CoInitializeEx(NULL, COINIT_MULTITHREADED);
GlobalData_t::s_ModuleInstance = reinterpret_cast<HINSTANCE>(DllHandle);
//register our debug zones
DEBUGREGISTER(reinterpret_cast<HINSTANCE>(DllHandle));
//don't want to be notified for threads attaching/detaching
DisableThreadLibraryCalls(reinterpret_cast<HMODULE>(DllHandle));
break;
case DLL_PROCESS_DETACH:
if (g_pApp)
{
g_pApp->Shutdown();
}
CoUninitialize();
MemTrackCheck();
break;
}
return TRUE;
}
/*------------------------------------------------------------------------------
Run
Description
Parameters:
c_pCommandLine:
Returns (HRESULT):
------------------------------------------------------------------------------*/
EXTERN_C
HRESULT
WINAPI Run(
__in_opt const WCHAR* c_pCommandLine
)
{
HANDLE SingletonHandle = NULL;
if (!PHRegisterSingletonApplication(
L"PhoneApp",
&SingletonHandle))
{
VoIPApp_t::s_SendCommandLine(c_pCommandLine);
return S_FALSE;
}
typedef HRESULT (* PFNINITIALIZERCDATA)(void);
PFNINITIALIZERCDATA InitRCData[] =
{
Layout_t::InitializeRCData,
Colors_t::InitializeRCData,
};
HRESULT hr;
for (int Index = 0; Index < _countof(InitRCData); Index++)
{
hr = InitRCData[Index]();
if (FAILED(hr))
{
ASSERT(0);
return hr;
}
}
//Initialize the common UI controls
if (!PHInitCommonControls())
{
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"Init PHCommon Controls"));
hr = E_FAIL;
goto exit;
}
//Create the application instance object
g_pApp = new VoIPApp_t();
if (g_pApp == NULL)
{
hr = E_OUTOFMEMORY;
PHONEAPP_DEBUGMSG(ZONE_PHONEAPP_ERROR, (L"OOM"));
goto exit;
}
hr = g_pApp->Run(c_pCommandLine);
//delete the app object
if (g_pApp)
{
delete g_pApp;
g_pApp = NULL;
}
exit:
//uninitialize the common controls
PHUnInitCommonControls();
//close handle
if (SingletonHandle != NULL)
{
CloseHandle(SingletonHandle);
}
return hr;
}
/*------------------------------------------------------------------------------
ProcessProvisionXML
Description
Parameters:
pInputBuffer:
ppOutputBuffer:
Returns (HRESULT):
------------------------------------------------------------------------------*/
EXTERN_C
HRESULT
WINAPI ProcessProvisionXML(
__in const WCHAR* pInputBuffer,
__deref_out_opt WCHAR** ppOutputBuffer
)
{
if (pInputBuffer == NULL)
{
return E_INVALIDARG;
}
if (ppOutputBuffer != NULL)
{
*ppOutputBuffer = NULL;
}
ce::auto_bstr bstrProvisionXML;
bstrProvisionXML = SysAllocString(pInputBuffer);
if (bstrProvisionXML == NULL)
{
return E_OUTOFMEMORY;
}
ProvisionManager_t ProvisionManager;
return ProvisionManager.ProcessXML(
bstrProvisionXML,
false,
ppOutputBuffer
);
}
/*------------------------------------------------------------------------------
ValidateProvisionXML
Description
Parameters:
pInputBuffer:
Returns (HRESULT):
------------------------------------------------------------------------------*/
EXTERN_C
HRESULT
WINAPI ValidateProvisionXML(
__in const WCHAR* pInputBuffer
)
{
if (pInputBuffer == NULL)
{
return E_INVALIDARG;
}
ce::auto_bstr bstrProvisionXML;
bstrProvisionXML = SysAllocString(pInputBuffer);
if (bstrProvisionXML == NULL)
{
return E_OUTOFMEMORY;
}
ProvisionManager_t ProvisionManager;
return ProvisionManager.ProcessXML(
bstrProvisionXML,
true
);
}
EXTERN_C
HRESULT
WINAPI MakePhoneCall(
__in const PH_MAKEPHONECALL_PARAMETERS* pParameters
)
{
if (pParameters == NULL ||
pParameters->StructSize != sizeof(PH_MAKEPHONECALL_PARAMETERS) ||
pParameters->DestAddress[0] == NULL )
{
return E_INVALIDARG;
}
HWND PhoneAppHandle = NULL;
//see if we can find the phone app window
PhoneAppHandle = PHGetAppWindow(phaPhoneApp, FALSE);
if (PhoneAppHandle == NULL)
{
//we can not find the window
return S_FALSE;
}
//initialize the data structure
COPYDATASTRUCT CopyDataStruct = {0};
CopyDataStruct.dwData = MAKE_PHONE_CALL;
CopyDataStruct.lpData = (PVOID)pParameters;
CopyDataStruct.cbData = pParameters->StructSize;
return (HRESULT)SendMessage(
PhoneAppHandle,
WM_COPYDATA,
0,
(LPARAM)&CopyDataStruct
);
}
EXTERN_C
HRESULT
WINAPI OnHookDialing(
const WCHAR CurrentChar
)
{
if (CurrentChar < L'0' || CurrentChar > L'9')
{
return E_INVALIDARG;
}
HWND PhoneAppHandle = NULL;
//see if we can find the phone app window
PhoneAppHandle = PHGetAppWindow(phaPhoneApp, FALSE);
if (PhoneAppHandle == NULL)
{
//we can not find the window
return S_FALSE;
}
SendMessage(
PhoneAppHandle,
WM_DIALED_DIGIT,
static_cast<WPARAM>(CurrentChar),
0
);
return S_OK;
}
//global accessors the rest of the application uses
VoIPApp_t* GetApp() { return g_pApp; }
IRTCClient* GetRTCClientPointer() { return GetApp()->GetRTCClientPointer(); }
#ifdef DEBUG
//Debug helper functions declared in debug.hpp
const CHAR* __PhoneApp_pFunctionName = NULL;
const WCHAR* __PhoneApp_pZoneName = NULL;
void
__phoneapp_debugset(
const WCHAR* pZoneName,
const CHAR* pFunctionName
)
{
__PhoneApp_pFunctionName = pFunctionName;
__PhoneApp_pZoneName = pZoneName;
}
void
__phoneapp_debugmsg(
const WCHAR* FormatString,
...
)
{
WCHAR ArgBuffer[MAX_PATH] = L"";
va_list List;
va_start(List, FormatString);
StringCchVPrintfW(
ArgBuffer,
_countof(ArgBuffer),
FormatString,
List
);
va_end(List);
DEBUGMSG(1, (L"%s %s %S - %s", MODULE_NAME, __PhoneApp_pZoneName, __PhoneApp_pFunctionName, ArgBuffer));
}
#else
void
__phoneapp_retailmsg(
const WCHAR* FormatString,
...
)
{
WCHAR ArgBuffer[MAX_PATH] = L"";
va_list List;
va_start(List, FormatString);
StringCchVPrintfW(
ArgBuffer,
_countof(ArgBuffer),
FormatString,
List
);
va_end(List);
RETAILMSG(1, (L"%s %s", MODULE_NAME, ArgBuffer));
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -