Spent a lot of effort developing a C# program based
on forum & sample PIMNavigator

Works fine for SEND

Works fine for FIRST RECEIVE Message
Subsequent INPUT Messages fail at
DAContentAccess.CAReadItem with code -2146435035

If I restart program works fine again for 1 PERCEIVE Message.
A huge amount of effort spent but all combinations failes.

please help

extract
public int CANotifyCallBack(int hCAHandle, int iReason, int iParam, IntPtr pItemID)
{
Console.WriteLine("Start of CANotifyCallBack"); // jnc

Console.WriteLine("iReason = " + iReason); // jnc

if (iReason == CAContentAccess.DAContentAccessDefinitions.CA_REASON_ITEM_ADDED)
{

Console.WriteLine("SMS Detected CA_REASON_ITEM_ADDED"); // jnc

intStatusCode = GetSMSDetails(pItemID);

if(intStatusCode==0) {

mobileno = "+91" + mobileno.Substring(mobileno.Length - 10, 10);

Console.WriteLine("India MobileNo = " + mobileno); // jnc

recvtext = recvtext.Replace("\n", "\\n");

recvtext = Regex.Replace(recvtext, @"[^\u0020-\u007F]", " ");

Console.WriteLine("CLEAN Text = " + recvtext); // jnc

OracleCommand cmdInsert = con.CreateCommand();
cmdInsert.CommandText = " INSERT INTO zsmstraffic " +
" (msgid,status,direction,msgdate,mobileno,smstext) " +
" VALUES (msgid_seq.nextval,'I','R',sysdate,'" + mobileno + "', '" + recvtext + "') ";

Console.WriteLine("SQL INSERT = " + cmdInsert.CommandText); // jnc

cmdInsert.ExecuteNonQuery();
cmdInsert.Dispose();

}

}

return 0;
}

//===================================================================
// GetSMSDetails
//
// Read selected SMS from phone and show details in list view.
//
//===================================================================
private int GetSMSDetails(IntPtr pItemID)
{
// Read SMS item data from device
Console.WriteLine("Start of GetSMSDetails"); // jnc

hOperHandle=0;

int iRet = DAContentAccess.CABeginOperation(intSMSHandle, 0,ref hOperHandle);

if (iRet != Errors.CONA_OK) {
Console.WriteLine("DAContentAccess.CABeginOperation Failed = " + iRet); // jnc
return 1;
}

// Creating the SMS-message object
CADataDefinitions.CA_DATA_MSG dataSMS = new CADataDefinitions.CA_DATA_MSG();

dataSMS.iSize = Marshal.SizeOf(dataSMS);
dataSMS.bAddressCount = 0;
dataSMS.iInfoField = 0;
dataSMS.iDataLength = 0;
dataSMS.pAddress = IntPtr.Zero;
dataSMS.pbData = IntPtr.Zero;

GetEmptyPIMDate(ref dataSMS.messageDate);

IntPtr pDataSMS = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CADataDefinitions.CA_DATA_MSG)));
Marshal.StructureToPtr(dataSMS, pDataSMS, true);

iRet = DAContentAccess.CAReadItem(hOperHandle,
pItemID,
0,
CADataDefinitions.CA_DATA_FORMAT_STRUCT,
pDataSMS);

if (iRet == Errors.CONA_OK)
{
// Copy data from buffer
dataSMS = (CADataDefinitions.CA_DATA_MSG)
Marshal.PtrToStructure(pDataSMS,
typeof(CADataDefinitions.CA_DATA_MSG));
}
else
{
Console.WriteLine("pItemID = " + pItemID); // jnc
Console.WriteLine("pDataSMS = " + pDataSMS); // jnc
Console.WriteLine("DAContentAccess.CAReadItem Failed = " + iRet); // jnc
int intStatusCode = DAContentAccess.CAEndOperation(hOperHandle);
return 1;
}

// Marshal.FreeHGlobal(buffer);

int iResult = DAContentAccess.CAEndOperation(hOperHandle);

if (iResult != Errors.CONA_OK) {
Console.WriteLine("DAContentAccess.CAEndOperation Failed = " + iResult); // jnc
return 1;
}


int i;
// Addresses
for (i = 0; i < dataSMS.bAddressCount; i++)
{
// Calculate beginning of CA_DATA_ITEM structure of item 'i'
Int64 iPtr = dataSMS.pAddress.ToInt64() + i * Marshal.SizeOf(typeof(CAContentAccess.CADataDefinitions.CA_DATA_ITEM));
// Convert integer to pointer
IntPtr ptr = new IntPtr(iPtr);
CAContentAccess.CADataDefinitions.CA_DATA_ADDRESS itemData;
itemData = (CAContentAccess.CADataDefinitions.CA_DATA_ADDRESS)Marshal.PtrToStructure(ptr, typeof(CAContentAccess.CADataDefinitions.CA_DATA_ADDRESS));

mobileno=itemData.pstrAddress;

Console.WriteLine("Received MobileNo = " + mobileno); // jnc
}

recvtext = " ";

if (dataSMS.iDataLength > 0)
{
if ((CADataDefinitions.CA_GET_DATA_FORMAT(dataSMS.iInfoField)) == CADataDefinitions.CA_DATA_FORMAT_UNICODE)
{
if (!IntPtr.Zero.Equals(dataSMS.pbData))
{

recvtext = Marshal.PtrToStringUni(dataSMS.pbData, dataSMS.iDataLength / 2);

Console.WriteLine("Received SMS Text = " + recvtext); // jnc

}
}
}

// // Free memory allocated by DA API
// iRet = DAContentAccess.CAFreeItemData(intSMSHandle, CADataDefinitions.CA_DATA_FORMAT_STRUCT, pDataSMS);
// if (iRet != Errors.CONA_OK) {
// Console.WriteLine("DAContentAccess.CAFreeItemData Failed = " + iRet); // jnc
// return 1;
// }

// Marshal.FreeHGlobal(pDataSMS);
// pDataSMS = IntPtr.Zero;

return 0;

}