private int ReadContact(DAContentAccessDefinitions.CA_ITEM_ID UID, ref CADataDefinitions.CA_DATA_CONTACT dataContact)
		{
			int hOperHandle = 0;
			int iRet = DAContentAccess.CABeginOperation(m_hCurrentConnection, 0, ref hOperHandle);
			if (iRet != PCCSErrors.CONA_OK)
			{
				//PCCAPIUtils.ShowErrorMessage("CABeginOperation", iRet);
				//syncEngine.CancelSync(PCCAPIUtils.CONAError2String(iRet));

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, PCCAPIUtils.CONAError2String(iRet), null);
			}
			dataContact.iSize = Marshal.SizeOf(dataContact);
			dataContact.bPICount = 0;
			dataContact.pPIFields = IntPtr.Zero;
			dataContact.bAddressCount = 0;
			dataContact.pAddressFields = IntPtr.Zero;
			dataContact.bNumberCount = 0;
			dataContact.pNumberFields = IntPtr.Zero;
			dataContact.bGeneralCount = 0;
			dataContact.pGeneralFields = IntPtr.Zero;
			// Allocate memory for buffers
			IntPtr buffer = Marshal.AllocHGlobal(Marshal.SizeOf(UID));
			Marshal.StructureToPtr(UID, buffer, true);
			UID.iSize = Marshal.SizeOf(typeof(DAContentAccessDefinitions.CA_ITEM_ID));
			m_pContactBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(dataContact));
			Marshal.StructureToPtr(dataContact, m_pContactBuffer, true);
			iRet = DAContentAccess.CAReadItem(hOperHandle, buffer, DAContentAccessDefinitions.CA_OPTION_USE_CACHE, CADataDefinitions.CA_DATA_FORMAT_STRUCT, m_pContactBuffer);
			if (iRet == PCCSErrors.CONA_OK)
			{
				// Copy data from buffer
				dataContact = (CADataDefinitions.CA_DATA_CONTACT)Marshal.PtrToStructure(m_pContactBuffer, typeof(CADataDefinitions.CA_DATA_CONTACT));
			}
			else
			{
				//PCCAPIUtils.ShowErrorMessage("CAReadItem", iRet);
				//syncEngine.CancelSync(PCCAPIUtils.CONAError2String(iRet));

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, PCCAPIUtils.CONAError2String(iRet), null);

				Marshal.FreeHGlobal(m_pContactBuffer);
				m_pContactBuffer = IntPtr.Zero;
			}
			Marshal.FreeHGlobal(buffer);
			int iResult = DAContentAccess.CAEndOperation(hOperHandle);
			if (iResult != PCCSErrors.CONA_OK)
			{
				//PCCAPIUtils.ShowErrorMessage("CAEndOperation", iResult);
				//syncEngine.CancelSync(PCCAPIUtils.CONAError2String(iRet));

				Dispatcher.Invoke(new SyncCancelEventHandler(owner.CancelSync),
						this, PCCAPIUtils.CONAError2String(iRet), null);
			}
			return iRet;
		}
Beispiel #2
0
        //=========================================================

        //=========================================================
        // CARegisterOperationCallback
        //
        // Description:
        //	Registers and unregisters callback function for operation 
        //  notifications
        //  
        // Parameters:
        //  hOperHandle	[in]	Handle to the existing API connection
        //	dwState		[in]	Used to define the action:
        //						 API_REGISTER used in registeration
        //						 API_UNREGISTER.used in removing the registeration
        //	pfnNotify	[in]	Function pointer of the call back method
        //
        // Return values:
        // PCCSErrors.CONA_OK
        // ECONA_INVALID_HANDLE
        // ECONA_NOT_INITIALIZED
        // ECONA_UNKNOWN_ERROR

        //=========================================================
        public static extern int CARegisterOperationCallback(
            int hOperHandle, 
            int iState, 
            DAContentAccessDefinitions.CAOperationCallbackDelegate pfnNotify
            );