📄 form.cpp
字号:
}
/******************************************************************************
CFormProvider::Init - Initialize the CFormProvider object
Params:
pszMsgClass[in] - message class of this form
Returns:
S_OK if we initialize properly
MAPI_E_NOT_ENOUGH_MEMORY if a memory allocation fails
Remarks:
Initializes the CFormProvider object, caching off the message class and
optionally initializing the property tags
******************************************************************************/
HRESULT WINAPI CFormProvider::Init(LPCWSTR pszMsgClass)
{
HRESULT hr = S_OK;
ASSERT(NULL != pszMsgClass);
ASSERT (m_pszMessageClass == NULL);
MAPI_EXIT_ON_NULL((m_pszMessageClass = new WCHAR[wcslen(pszMsgClass) + 1]));
wcscpy(m_pszMessageClass, pszMsgClass);
Exit:
return S_OK;
}
// **************************************************************************
// Function Name: CleanUpReadForm
//
// Purpose: Do cleanup of any already-open read form handles.
//
// Arguments:
// None.
//
// Return Values:
// S_OK is always returned
//
// Side effects:
// All MAPI handles are released.
//
// Description:
// Releases the reference held on the message, message store, and MAPI
// session.
/******************************************************************************
CFormProvider::CleanUpReadForm - Cleanup any already-opened read form
allocations
Params:
None
Returns:
S_OK
Remarks:
Releases all the the CEMAPI stuff
******************************************************************************/
HRESULT CFormProvider::CleanUpReadForm()
{
// Release the message and message store
SAFE_RELEASE(m_pMsgStore);
// Release session object last
SAFE_RELEASE(m_pSession);
return S_OK;
}
/******************************************************************************
ExtractPicsFromBody - Parses the body of the message for picture objects
and text we want to display
Returns:
S_OK on success, E_xxx OTW
Remarks:
We expect the body to be in a certain format. This is defined in the EMS
Rule client sample code.
******************************************************************************/
HRESULT ExtractPicsFromBody(LPTSTR pszBody,
UINT* puNumPics,
LPEMSPICINFO* ppEMSPics)
{
HRESULT hr = E_FAIL;
TCHAR* pCurr = pszBody;
TCHAR* pTemp = NULL;
TCHAR* pEnd = NULL;
UINT uIndex = 0;
UINT uCount = 0;
UINT uNumObj = 0; //Total object count
TCHAR szBuffer[10] = _T("");
//Validate params
ASSERT(pszBody);
ASSERT(puNumPics);
ASSERT(ppEMSPics);
if((NULL == pszBody) || (NULL == puNumPics) || (NULL == ppEMSPics))
{
goto Exit;
}
//Read in the total number of objects
*puNumPics = 0;
pCurr += _tcslen(kszEMSID); //Skip the GUID Message ID
//The next 2 TCHARS is the object count in HEX
memcpy(szBuffer, pCurr, sizeof(TCHAR)*2);
uNumObj = _tcstol(szBuffer, &pTemp, 16);
pCurr += 2; //Now point to 1st object
ZeroMemory(szBuffer, sizeof(szBuffer));
ASSERT(uNumObj);
//Now allocate space for each object, these might not all
//get used if we have objects other than pictures
*ppEMSPics = (LPEMSPICINFO)malloc(sizeof(EMSPICINFO)*uNumObj);
ZeroMemory(*ppEMSPics, sizeof(EMSPICINFO)*uNumObj);
if(NULL == *ppEMSPics)
{
goto Exit;
}
//Now read in each object
while(uCount++ < uNumObj)
{
UINT uSize = 0;
UINT uID = 0;
//First 4 TCHARS is the object size
memcpy(szBuffer, pCurr, sizeof(TCHAR)*4);
uSize = _tcstol(szBuffer, &pTemp, 16);
ZeroMemory(szBuffer, sizeof(szBuffer));
ASSERT(uSize);
pCurr +=4; //skip to object data
//The next 2 TCHARS should be a picture ID
//either 0x10, 0x11, or 0x12
memcpy(szBuffer, pCurr, sizeof(TCHAR)*2);
uID = _tcstol(szBuffer, &pTemp, 16);
ZeroMemory(szBuffer, sizeof(szBuffer));
if(((uID >= 0x10) && (uID <= 0x12)) || (uID == 0xFF))
{
(*puNumPics)++; //found a supported object, PICTURE
pCurr += 2;
if(uID != 0xFF) //IEI_TEXT_ONLY skips this
{
//OFFSET
memcpy(szBuffer, pCurr, sizeof(TCHAR)*2);
(*ppEMSPics + uIndex)->uOffset = _tcstol(szBuffer, &pTemp, 16);
ZeroMemory(szBuffer, sizeof(szBuffer));
//HRES
pCurr += 2;
memcpy(szBuffer, pCurr, sizeof(TCHAR)*2);
(*ppEMSPics + uIndex)->uHRes = _tcstol(szBuffer, &pTemp, 16);
ZeroMemory(szBuffer, sizeof(szBuffer));
//VRES
pCurr += 2;
memcpy(szBuffer, pCurr, sizeof(TCHAR)*2);
(*ppEMSPics + uIndex)->uVRes = _tcstol(szBuffer, &pTemp, 16);
ZeroMemory(szBuffer, sizeof(szBuffer));
//PIXEL DATA
UINT uSizePixels = ((*ppEMSPics + uIndex)->uHRes/4) *
(*ppEMSPics + uIndex)->uVRes;
pCurr += 2;
(*ppEMSPics + uIndex)->pszData =
(TCHAR*)malloc(sizeof(TCHAR) * (uSizePixels + 1));
//Fill with byte pattern for debugging
memset((*ppEMSPics + uIndex)->pszData, 0xBB, sizeof(TCHAR) * (uSizePixels + 1));
//Copy picture data
memcpy((*ppEMSPics + uIndex)->pszData, pCurr,
sizeof(TCHAR) * uSizePixels);
//Append NULL
*((*ppEMSPics + uIndex)->pszData + uSizePixels) = _T('\0');
//TEXT LEN
pCurr += uSizePixels;
}
//Get the length of the text
memcpy(szBuffer, pCurr, sizeof(TCHAR)*2);
UINT uTextLen = _tcstol(szBuffer, &pTemp, 16);
ZeroMemory(szBuffer, sizeof(szBuffer));
pCurr += 2;
//TEXT (IF EXISTS)
if(uTextLen)
{
//Allocate storage
(*ppEMSPics + uIndex)->pszText = (TCHAR*)malloc(
sizeof(TCHAR) * (uTextLen + 1));
ZeroMemory((*ppEMSPics + uIndex)->pszText, sizeof(TCHAR) * (uTextLen + 1));
//copy the text
_tcsncpy((*ppEMSPics + uIndex)->pszText, pCurr, uTextLen);
pCurr += uTextLen;
}
uIndex++;
}
else
{
//Somehow an object ID we aren't expecting got here
ASSERT(TRUE);
}
}
hr = S_OK; //Everything was processed ok
Exit:
return hr;
}
/******************************************************************************
ConvertToMonoBitmap - Converts info obtained from ExtractPicsFromBody()
into a monochrome formatted BITMAP.
******************************************************************************/
HRESULT ConvertToMonoBitmap(UINT uNumPics,
LPEMSPICINFO* ppEMSPics,
LPBITMAP pBitmap)
{
HRESULT hr = E_FAIL;
UINT uCount = 0;
LPBYTE pDest = NULL; //Bitmap pixel data
TCHAR* pSrc = NULL; //String data from EMS
UINT uConv = 0; //converted byte storage
TCHAR szBuffer[3] = _T(""); //String byte to convert
TCHAR* pTemp = NULL; //conversion end marker
//Validate params
ASSERT(uNumPics);
ASSERT(ppEMSPics);
ASSERT(pBitmap);
if((NULL == pBitmap) || (NULL == ppEMSPics))
{
goto Exit;
}
//Process each pic
while(uCount < uNumPics)
{
//Convert each byte to monochrome format, byte by byte
//0 = BLACK, 1 = WHITE
UINT uLen;
UINT uCurr;
//Find start of data to convert
pSrc = (*ppEMSPics + uCount)->pszData;
if(NULL == pSrc) //Text only, has no picture data
{
//skip it
uCount++;
continue;
}
//Get the length of the data
uLen = _tcslen(pSrc);
//Allocate space for the bits
(pBitmap + uCount)->bmBits = malloc((*ppEMSPics + uCount)->uHRes/4 *
(*ppEMSPics + uCount)->uVRes);
//Set info on the bitmap
(pBitmap + uCount)->bmType = 0;
(pBitmap + uCount)->bmPlanes = 1;
(pBitmap + uCount)->bmBitsPixel = 1;
(pBitmap + uCount)->bmWidth = (*ppEMSPics + uCount)->uHRes;
(pBitmap + uCount)->bmHeight = (*ppEMSPics + uCount)->uVRes;
(pBitmap + uCount)->bmWidthBytes = (*ppEMSPics + uCount)->uHRes/4;
//Do the conversion
for(uCurr = 0; uCurr < uLen; uCurr++)
{
//First convert the string to hex
ZeroMemory(szBuffer, sizeof(szBuffer));
memcpy(szBuffer, pSrc, sizeof(TCHAR)*2);
uConv = ~(_tcstol(szBuffer, &pTemp, 16));
//Invert the number and store it
memcpy(
LPBYTE((pBitmap + uCount)->bmBits) + uCurr,
(LPBYTE)&uConv,
1);
pSrc+=2;
}
uCount++;
}
hr = S_OK;
Exit:
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -