Search code examples
c++pointersexchangewebservicesdereferencegsoap

How to dereference pointer when pointee value assigned in response


I want to dereference a pointer firsm->RootFolder->TotalItemsInView which takes value, when response is arrived.

ns1__MessageType* messgT = new ns1__MessageType();
std::vector<ns1__MessageType> v;
int count;

ews__FindItemResponseMessageType *firsm = new ews__FindItemResponseMessageType();
firsm->RootFolder = new ns1__FindItemParentType();
count = *firsm->RootFolder->TotalItemsInView;

for(int i=0; i < count; i++){
    v.push_back(messgT[i]);
    std::cout << "Hello"  << std::endl;
}

TotalItemsInView is defined in class of ns1__FindItemParentType.

class ns1__FindItemParentType
{ public:
       int* TotalItemsInView ;
};

Here the TotalItemsInView will have integer value in response of SOAP request. I want to use that integer value in count to run the 'for loop' that many times.

In compilation I've got Segmentation fault may be because of Empty value at TotalItemsInView, but in response it will have value, so how can i do that. I'm new to pointers, Any help appreciated. Thank you.

UPDATE: My XML Received log:

<m:FindItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
    <m:ResponseMessages>
        <m:FindItemResponseMessage ResponseClass="Success">
            <m:ResponseCode>NoError</m:ResponseCode>
            <m:RootFolder TotalItemsInView="2" IncludesLastItemInRange="true">
                <t:Items>
                    <t:Message>
                        <t:ItemId Id="b30rTZMma5" ChangeKey="CQAAABAAAAAWl"/>
                    </t:Message>
                    <t:Message>
                        <t:ItemId Id="tNFsAAAIFUA" ChangeKey="CQAAAAAAWT"/>
                    </t:Message>
                </t:Items>
            </m:RootFolder>
        </m:FindItemResponseMessage>
    </m:ResponseMessages>
</m:FindItemResponse>

Solution

  • I was wrong here at firsm->RootFolder = new ns1__FindItemParentType() where i tried to initialize a response structure with empty value, that's way i've problem in derefrencing it. So thr right way to do so is

    ews__FindItemResponseMessageType *firsm = new ews__FindItemResponseMessageType();
    firsm = findItemRes.ews__FindItemResponse->ResponseMessages->__union_ArrayOfResponseMessagesType->union_ArrayOfResponseMessagesType.FindItemResponseMessage;
    count = *firsm->RootFolder->TotalItemsInView;