none
Application get crashed while calling HrQueryAllRows with SRestriction in Visual Studio - 2010 RRS feed

  • Question

  • Hi All,

    We are using the MAPI for copying the emails from exchange mailbox to the PST file. The following implementation works fine in the Visual Studio 2003 setup, However it crashes in the Visual Studio 2010. Currently we are trying to compile the source in Visual Studio 2010 compiler. We are trying the following in our code.

    1. Listing the emails based on the following
    Subject, Sender, Date and time received.

        To implement this we have applied the SRestriction in the MAPI Table using the following Property.

    Properties :
                PR_MESSAGE_DELIVERY_TIME, PR_DISPLAY_TO, PR_SUBJECT

        sres => Contains above restrictions.

        when we call this code application get crashed in VS-2010 compiler. But the same works fine in 2003 compiler.

       hRes = HrQueryAllRows(pmt,(SPropTagArray*)&foldcols,&sres ,&sosName,0,&frows);

        To confirm the SRestriction is only the issue in the code, we have tried to pass the NULL for SRestriction field. Now the operation completed successfully without any SRestriction value.

        Please any one suggest to resolve the issue. Is there any problems use the SRestriction in VS-2010 ?....

    Regards,
    Marimuthu.M

                                        
    • Moved by Naomi N Thursday, May 3, 2012 3:18 PM Possibility of the better answer (From:Suggestions and Feedback for the Forums)
    • Moved by lucy-liu Friday, May 4, 2012 9:13 AM it is a outlook issue (From:Visual Studio Editor)
    Thursday, May 3, 2012 6:51 AM

Answers

  • I just spotted the problem. This variable:

    SRestriction toCCLevel[2];

    is declared in an inner scope, but you continued to use it after it went out of scope. If this didn't crash before it's because you got lucky and the memory didn't get resued. You need to move the declaration to the outer scope.

    Wednesday, May 9, 2012 4:35 AM
    Answerer

All replies

  • Hi Marimuthu,

    This is a Outlook issue, I will move it to Outlook for Developers forum for a better support.

    Thank you for your understanding!


    Lucy Liu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, May 4, 2012 9:13 AM
  • I use VS2010 to build MFCMAPI, which has no problems with SRestriction.

    Could you share the code you used to build sres? And also, what do you mean when you say "get crashed in VS-2010 compiler"? Are you saying the compiler crashed? Or are you saying your application crashed? If it was your application, what was the nature of the crash? What line of your code did it crash on?

    Friday, May 4, 2012 1:08 PM
    Answerer
  • Hi Stephen,

    See my sample code here

    SizedSPropTagArray(9,foldcols) = {9, {PR_SUBJECT, PR_SENT_REPRESENTING_NAME, PR_MESSAGE_DELIVERY_TIME, 
    		PR_DISPLAY_BCC, PR_DISPLAY_CC, PR_DISPLAY_TO, PR_BODY, PR_HASATTACH, PR_MESSAGE_SIZE}};
    SRowSet *frows = NULL;
    
    string fromStr = "sender"
    string toStr = "receive"
    string subjectStr = "Sample"
    string contentStr = "Message"
    
    int filterCnt = 0;
    if(subjectStr.length() > 0) filterCnt++;
    
    if(fromStr.length() > 0) filterCnt++;
    
    if(toStr.length() > 0) 	filterCnt = filterCnt++;
    
    if(contentStr.length() > 0) filterCnt++; 
    
    SRestriction    sres;
    SRestriction    *sresAnyLevel = (SRestriction*) malloc(filterCnt * sizeof(SRestriction));
    SRestriction    timeSresLevel[2];
    SRestriction	combineLevel[2];
    
    SPropValue fromProp;
    SPropValue toProp;			
    SPropValue ccProp;
    SPropValue subjectProp;
    SPropValue contentProp;
    SPropValue stTimeProp;
    SPropValue endTimeProp;
    
    fromProp.ulPropTag = PR_SENT_REPRESENTING_NAME;
    fromProp.Value.lpszA = (char *)fromStr.c_str();
    
    toProp.ulPropTag = PR_DISPLAY_TO;
    toProp.Value.lpszA = (char *)toStr.c_str();
    
    ccProp.ulPropTag = PR_DISPLAY_CC;
    ccProp.Value.lpszA = (char *)toStr.c_str();
    
    subjectProp.ulPropTag = PR_SUBJECT;
    subjectProp.Value.lpszA = (char *)subjectStr.c_str();
    
    contentProp.ulPropTag = PR_BODY;
    contentProp.Value.lpszA = (char *)contentStr.c_str();
    
    stTimeProp.ulPropTag = PR_MESSAGE_DELIVERY_TIME;
    stTimeProp.Value.ft.dwLowDateTime = (DWORD)startFileTime;
    stTimeProp.Value.ft.dwHighDateTime = startFileTime >> 32;
    
    endTimeProp.ulPropTag = PR_MESSAGE_DELIVERY_TIME;
    endTimeProp.Value.ft.dwLowDateTime = (DWORD)endFileTime;
    endTimeProp.Value.ft.dwHighDateTime = endFileTime >> 32;
    
    int indexPos = 0;
    
    if(subjectStr.length() > 0)
    {
    	sresAnyLevel[indexPos].rt = RES_CONTENT;
    	sresAnyLevel[indexPos].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    	sresAnyLevel[indexPos].res.resContent.ulPropTag = PR_SUBJECT;
    	sresAnyLevel[indexPos].res.resContent.lpProp = &subjectProp;
    	indexPos++;
    }
    if(fromStr.length() > 0)
    {
    	sresAnyLevel[indexPos].rt = RES_CONTENT;
    	sresAnyLevel[indexPos].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    	sresAnyLevel[indexPos].res.resContent.ulPropTag = PR_SENT_REPRESENTING_NAME;
    	sresAnyLevel[indexPos].res.resContent.lpProp = &fromProp;
    	indexPos++;
    }
    if(toStr.length() > 0)
    {
    	SRestriction	toCCLevel[2];
    	toCCLevel[0].rt = RES_CONTENT;
    	toCCLevel[0].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    	toCCLevel[0].res.resContent.ulPropTag = PR_DISPLAY_TO;
    	toCCLevel[0].res.resContent.lpProp = &toProp;
    	
    	toCCLevel[1].rt = RES_CONTENT;
    	toCCLevel[1].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    	toCCLevel[1].res.resContent.ulPropTag = PR_DISPLAY_CC;
    	toCCLevel[1].res.resContent.lpProp = &ccProp;
    	
    	sresAnyLevel[indexPos].rt = RES_OR;
    	sresAnyLevel[indexPos].res.resOr.cRes = 2;
    	sresAnyLevel[indexPos].res.resOr.lpRes = toCCLevel;
    	indexPos++;
    }
    if(contentStr.length() > 0)
    {
    	sresAnyLevel[indexPos].rt = RES_CONTENT;
    	sresAnyLevel[indexPos].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    	sresAnyLevel[indexPos].res.resContent.ulPropTag = PR_BODY;
    	sresAnyLevel[indexPos].res.resContent.lpProp = &contentProp;
    }
    
    combineLevel[0].rt = RES_OR;
    combineLevel[0].res.resOr.cRes = filterCnt;
    combineLevel[0].res.resOr.lpRes = sresAnyLevel;
    
    timeSresLevel[0].rt = RES_PROPERTY;
    timeSresLevel[0].res.resProperty.relop = RELOP_GE;
    timeSresLevel[0].res.resProperty.ulPropTag = PR_MESSAGE_DELIVERY_TIME;
    timeSresLevel[0].res.resProperty.lpProp = &stTimeProp;
    
    timeSresLevel[1].rt = RES_PROPERTY;
    timeSresLevel[1].res.resProperty.relop = RELOP_LE;
    timeSresLevel[1].res.resProperty.ulPropTag = PR_MESSAGE_DELIVERY_TIME;
    timeSresLevel[1].res.resProperty.lpProp = &endTimeProp;
    
    combineLevel[1].rt = RES_AND;
    combineLevel[1].res.resAnd.cRes = 2;
    combineLevel[1].res.resAnd.lpRes = timeSresLevel;
    
    sres.rt = RES_OR;
    sres.res.resOr.cRes = 2;
    sres.res.resOr.lpRes = combineLevel;
    
    hRes = HrQueryAllRows(pmt,(SPropTagArray*)&foldcols,&sres ,&sosName,0,&frows);
    free(sresAnyLevel);

    The above code works fine, if we compile the source in 2003 compiler, However same code get crashed in the below scenario in (HrQueryAllRows).

    Success Scenario :

    In the above code, When we didn't apply restriction on (PR_DISPLAY_TO and PR_DISPLAY_CC) properties then 2010 compiled code works fine.

    Failure Scenario :

    In the above code if we apply restriction for (PR_DISPLAY_TO and PR_DISPLAY_CC) along with some other properties like PR_SENT_REPRESENTING_NAME, PR_SUBJECT, PR_MESSAGE_DELIVERY_TIME then application get crashed while doing (HrQueryAllRows).

    Since still now we are using 2003 for the application development, so no issues in that. Currently we are trying to compile our source code in VS2010 but it crashed while calling (HrQueryAllRows).

    Any thing am doing wrong... please correct me...

    Regards,
    Marimuthu.M


    • Edited by MarimuthuNew49 Saturday, May 5, 2012 10:24 AM Some contents added
    Saturday, May 5, 2012 10:23 AM
  • One thing that stands out is you use property macros such as PR_SUBJECT, but set an ansi string to lpszA. This is fine as long as Unicode isn't defined, because PR_SUBJECT will map to PR_SUBJECT_A, which is of type PT_STRING8. But if Unicode is defined, PR_SUBJECT will map to PR_SUBJECT_W, which is of type PT_UNICODE. This would then conflict with the string you have set. So this is unsafe code to write. Safer code would explictly use PR_SUBJECT_A (as well as the _A variants of the other string properties).

    If that doesn't fix the problem, I would try reducing your restriction until you come up with the smallest one that can still cause a problem. That's usually enough to expose the issue.

    Monday, May 7, 2012 1:16 PM
    Answerer
  • Hi Stephen,

    I tried with your requested changes (PR_SUBJECT_A), but still no luck. Now application exited with the error EXCEPTION_STACK_OVERFLOW. Also i tried the following,

    if(toStr.length() > 0)
    			{
    /* * /
    				SRestriction	toCCLevel[2];
    				toCCLevel[0].rt = RES_CONTENT;
    				toCCLevel[0].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    				toCCLevel[0].res.resContent.ulPropTag = PR_DISPLAY_TO_A;
    				toCCLevel[0].res.resContent.lpProp = &toProp;
    				
    				toCCLevel[1].rt = RES_CONTENT;
    				toCCLevel[1].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    				toCCLevel[1].res.resContent.ulPropTag = PR_DISPLAY_CC_A;
    				toCCLevel[1].res.resContent.lpProp = &ccProp;
    				
    				sresAnyLevel[indexPos].rt = RES_OR;
    				sresAnyLevel[indexPos].res.resOr.cRes = 2;
    				sresAnyLevel[indexPos].res.resOr.lpRes = toCCLevel;
    				indexPos++;
    /* */
    				/* */
    				sresAnyLevel[indexPos].rt = RES_CONTENT;
    				sresAnyLevel[indexPos].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    				sresAnyLevel[indexPos].res.resContent.ulPropTag = PR_DISPLAY_TO;
    				sresAnyLevel[indexPos].res.resContent.lpProp = &toProp;
    				indexPos++;
    
    				sresAnyLevel[indexPos].rt = RES_CONTENT;
    				sresAnyLevel[indexPos].res.resContent.ulFuzzyLevel = FL_SUBSTRING|FL_IGNORECASE;
    				sresAnyLevel[indexPos].res.resContent.ulPropTag = PR_DISPLAY_CC;
    				sresAnyLevel[indexPos].res.resContent.lpProp = &ccProp;
    				indexPos++;
    				/* */
    			}

    I have changed the above code in my previous post. Now it is working fine. But we can't use this in our filter settings for the emails. Since if we use the PR_DISPLAY_To and PR_DISPLAY_CC in seperate then no emails will be listed at the end of restriction. Because the given email id will be available in either To or CC. 

    So here the problem is when we apply RES_OR restriction for PR_DISPLAY_TO and PR_DISPLAY_CC then application exited with the above error. If we separately create the restriction then no issues.

    Any suggestion on this.

    Regards,

    Marimuthu.M

    Tuesday, May 8, 2012 7:49 AM
  • I just spotted the problem. This variable:

    SRestriction toCCLevel[2];

    is declared in an inner scope, but you continued to use it after it went out of scope. If this didn't crash before it's because you got lucky and the memory didn't get resued. You need to move the declaration to the outer scope.

    Wednesday, May 9, 2012 4:35 AM
    Answerer
  • Hi Stephen,

    Thanks a lot.  After changing the declaration scope, now my application works fine. But why 2003 compiled code works fine... that is strange....

    HURRAH.....

    Marimuthu.M

    Thursday, May 10, 2012 12:17 PM