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

📄 vcal.cxx

📁 这个是微软WINCE的OBEX协议例子
💻 CXX
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/**************************************************************************/
/*  VCal.cxx                                                              */
/*                                                                        */
/*  This file contains routines to process VCals						  */
/*                                                                        */
/*  DISCLAIMER!!!:  this does not FULLY support the vCard spec            */
/*     it is intended as an example to the OBEX Inbox and nothing more    */
/*     I dont believe it will cause harm or behave strangly, but use it   */
/*     at your own risk!                                                  */
/*                                                                        */
/*                                                                        */
/*	*'ed Functions are DLL entry points                                   */
/*                                                                        */
/*  Functions included:                                                   */
/*     *OBEXInboxClient     --   the entry point from the OBEX inbox      */
/*                                                                        */
/*  Other related files:                                                  */
/*                                                                        */
/*                                                                        */
/**************************************************************************/
#include <winsock.h>
#include <bldver.h>
#include "VUtils.h"


/*****************************************************************************/
/*   DllMain                                                                                                                      */
/*	 just diable thread library calls	 										         */
/*****************************************************************************/
BOOL APIENTRY DllMain(HANDLE hInst, DWORD dwReason, LPVOID lpReserved) 
{
	if (dwReason == DLL_PROCESS_ATTACH) 
		DisableThreadLibraryCalls((HMODULE)hInst);
	return TRUE;
}

/*****************************************************************************/
/*   OBEXInboxClient                                                         */
/*   Handle requests from the Inbox for vCals								 */
/*                                                                           */
/*   Begin by creating a memory map to the the passed in file name           */
/*	    then open the Appointments Database, parse out all interesting items */
/*		from the vCal and insert them into the DB.  afterwards clean up and  */
/*		then close handles before returning									 */
/*****************************************************************************/
BOOL OBEXInboxClient(LPCTSTR objectName)
{	
    
	//SETUP phase] -----------------------------------------------------------
	//  create a memory map to the file passed in, and open up the 
	//  Contacts Database
	LPVOID data;
	char *lpDataPtr;
	int retVal = 0;
	
	HANDLE hFileMap, hFileMapping;
	hFileMap = CreateFileForMapping(objectName, 
		GENERIC_READ, 
		FILE_SHARE_READ,
		NULL, 
		OPEN_EXISTING, 
		FILE_ATTRIBUTE_NORMAL, 
		NULL);
	
    //if there was an error opening the file, exit
	if(hFileMap == INVALID_HANDLE_VALUE) 
	{		
		ASSERT(FALSE);
		return 1;
	}
	
    //create a file mapping object,  on error exit
	hFileMapping = 
		CreateFileMapping(hFileMap, 
		NULL, 
		PAGE_READONLY, 
		0,0, 
		NULL);
	
	if(hFileMapping == NULL) {		
		ASSERT(FALSE);
		CloseHandle(hFileMap); 
		return 1;
	}
	
    //now that the file as been opened and mapped, 
	//  create the map, and point lpDataPtr to the data
	data = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0,0,0);	
	lpDataPtr = (char *)data;
	
    //open the contacts database
    CEOID  WceObjID = 0;
	HANDLE hDB = CeOpenDatabase(&WceObjID, _T("Appointments Database"), 0, CEDB_AUTOINCREMENT, NULL);
	
	if(hDB == INVALID_HANDLE_VALUE)
	{
		ASSERT(FALSE);
		UnmapViewOfFile(data);
		CloseHandle(hFileMapping);
		CloseHandle(hFileMap);
		return 1;
	}
	

    //PARSE/INSERT phase] -----------------------------------------------------
    //   from here down start the parsing of the data and place records
    //   into the database
    //
    //   The core of the parsing is in the functino ParseVCard
    //   it will parse out one (and only one) vCal. it returns
    //   a pointer to the end of the vCard entry it just parsed.
    //   this allows for a loop to be created that parses/inserts
    //   one record at a time
    //
    //   BUGBUG: multiple vCard NOT supported yet
//	while(lpDataPtr)
	{
		//insert other required fields
		CEPROP_LIST *CL = new CEPROP_LIST();
		CEPROP_LIST *pCL = CL;
		CL->prop = new CEPROPVAL();
		memset(CL->prop, 0, sizeof(CEPROPVAL));
		CL->prop->propid = HHPR_APPT_STATE;//0x0f
		CL->prop->val.iVal = 0;//from 0

		CEPROP_LIST *pTemp = NULL;
		CL->pNext = new CEPROP_LIST;
		pTemp=CL->pNext;
		pTemp->prop = new CEPROPVAL();
		memset(pTemp->prop, 0, sizeof(CEPROPVAL));
		pTemp->prop->propid = HHPR_ACTION_TYPE;//0x450A
		pTemp->prop->val.lVal = 13;

		pTemp->pNext = new CEPROP_LIST;
		pTemp=pTemp->pNext;
		pTemp->prop = new CEPROPVAL();
		memset(pTemp->prop, 0, sizeof(CEPROPVAL));
		pTemp->prop->propid = HHPR_APPT_RECURRING_FLAG;//0x4223
		pTemp->prop->val.boolVal = 0;
				
		pTemp->pNext = new CEPROP_LIST;
		pTemp=pTemp->pNext;
		pTemp->prop = new CEPROPVAL();
		memset(pTemp->prop, 0, sizeof(CEPROPVAL));
		pTemp->prop->propid = HHPR_PRIVATE;//0x4
		pTemp->prop->val.iVal = 0;
		
		
		pTemp->pNext = new CEPROP_LIST;
		pTemp=pTemp->pNext;
		pTemp->prop = new CEPROPVAL();
		memset(pTemp->prop, 0, sizeof(CEPROPVAL));
		pTemp->prop->propid = HHPR_ACTION_DEFAULT_PARAM;//0x4509
		pTemp->prop->val.lpwstr = new WCHAR[10];
		swprintf(pTemp->prop->val.lpwstr, _T("TESTING"));
		
		pTemp->pNext = new CEPROP_LIST;
		pTemp=pTemp->pNext;
		pTemp->prop = new CEPROPVAL();
		memset(pTemp->prop, 0, sizeof(CEPROPVAL));
		pTemp->prop->propid = HHPR_ACTION_ACTIVE;//0x4503
		pTemp->prop->val.boolVal = FALSE;
		
		pTemp->pNext = new CEPROP_LIST;
		pTemp=pTemp->pNext;
		pTemp->prop = new CEPROPVAL();
		memset(pTemp->prop, 0, sizeof(CEPROPVAL));
		pTemp->prop->propid = HHPR_ACTION_OFFSET;//0x4501
		pTemp->prop->val.lVal = 15;
		
		//clear out the next ptr
		pTemp->pNext = NULL;


		//process the VCARD
        VCalStateObj vcState;
        memset(&vcState, 0, sizeof(vcState));
        OID_STRUCT pPassStruct;
        pPassStruct.uiNumElements = g_CalendarSize;
        pPassStruct.pTrans = g_sCalendarOidTranslator;
		lpDataPtr = ParseVCard(pCL, &pPassStruct, lpDataPtr, &vcState);
	
                long uiDurationMin = 1;
        long subType = 0;
        //if there is a start and stop time, calculate the differences 
        //   (in min) of the 2
        if(vcState.stopTime && vcState.startTime)
        {
            _int64 timeStart, timeStop, duration;
            
            timeStop = vcState.stopTime->dwHighDateTime;
            timeStop <<= 32;
            timeStop |= vcState.stopTime->dwLowDateTime;
            
            timeStart = vcState.startTime->dwHighDateTime;
            timeStart <<= 32;
            timeStart |= vcState.startTime->dwLowDateTime;
            
            duration = (timeStop - timeStart);
            duration /= 10000000;
            duration /= 60;
            
            uiDurationMin = (long)duration;
        }
        //if the stop time is given, dont use the all day subtype
        if(vcState.stopTime)
            subType = 2;
        else
            subType = 1;
        
        
        //chain in the subtype
        CEPROP_LIST *pSub = new CEPROP_LIST;
        pSub->prop = new CEPROPVAL();
        memset(pSub->prop, 0, sizeof(CEPROPVAL));
        pSub->prop->propid = HHPR_APPT_SUBTYPE;//0x4215
        pSub->prop->val.lVal = subType;
        
        
        pCL = CL;
        while(pCL && pCL->pNext)
            pCL = pCL->pNext;
        
        //chain in the duration
        if(pCL)
        {
            pSub->pNext = pCL->pNext;
            pCL->pNext = pSub;
        }
        
        
        
        
        //chain in the duration
        CEPROP_LIST *pDur = new CEPROP_LIST;
        pDur->prop = new CEPROPVAL();
        memset(pDur->prop, 0, sizeof(CEPROPVAL));
        pDur->prop->propid = HHPR_APPT_DURATION;//0x4213
        pDur->prop->val.lVal = uiDurationMin;
        
        
        pCL = CL;
        while(pCL && pCL->pNext)
            pCL = pCL->pNext;
        
        //chain in the duration
        if(pCL)
        {
            pDur->pNext = pCL->pNext;
            pCL->pNext = pDur;
        }
        
        
        
        
        //INSERT phase] --------------------------------------------------------
		//   at this point, we have a linked list of CEPROP's that need
		//   to be placed into the Contacts Database.  rather than
		//   chaining them into one big array (as expected by CeWriteRecordProps
		//   (that would require more memory... possibly WAY more on big
		//   records and lots of memory moving) just make multiple calls to
		//   CeWriteRecordProps sending in one record at a time
		pCL = CL;
		if(pCL && pCL->prop)
		{
			ASSERT(pCL->prop);
			
			if(pCL->prop)
			{
				CEOID retOID = CeWriteRecordProps(hDB, 0, 1, pCL->prop); 
				pCL = pCL->pNext;
				if(retOID != 0)
				{
					while(pCL)
					{
						ASSERT(pCL->prop);
						if(pCL->prop)
						{
							CEOID r2OID = 
                                CeWriteRecordProps(hDB, retOID, 1, pCL->prop);
							if(r2OID == 0) 
							{							
								break;
							}
						}						
						pCL=pCL->pNext;
					}
				}
				else
				{
                    retVal = 1; //this avoids a goto
				}
			}		
		}
	
		
		//clean up memory
		pCL=CL;
		while(pCL) 
		{
			if(pCL->prop)
			{
				if(LOWORD(pCL->prop->propid) == CEVT_LPWSTR &&
					pCL->prop->val.lpwstr)
                {
					delete [] pCL->prop->val.lpwstr;
                }               

				delete pCL->prop;
			}
			
			CEPROP_LIST *pOld = pCL;
			pCL = pCL->pNext;

			if(pOld)
            {
				delete pOld;
            }
		}

        //cleanup global state
        if(vcState.startTime)
        {
            delete vcState.startTime;
        }
        if(vcState.stopTime)
        {
             delete vcState.startTime;
        }	
	}
	
	CloseHandle(hDB);
	UnmapViewOfFile(data);
	CloseHandle(hFileMapping);
	CloseHandle(hFileMap);

    Debug_PrintMemUsage(5);

    //delete the file
    DeleteFile(objectName); 
	return retVal;
}

⌨️ 快捷键说明

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