How to calculate context hash in CT_TextCharRangeContext elements?

Sándor Kolumbán 1 Reputation point

Dear MS Support!

We are consuming and modifying pptx files in a native manner and we stumbled upon an issue when modifying contents around modern comments.

According to the schema file describing the location of modern comments (, an element of type CT_TextCharRangeContext describes the context of a comment.

These elements have a hash attribute which is required, but we found no documentation on how to update this hash value.

<xsd:complexType name="CT_TextCharRangeContext">  
     <xsd:attribute name="len" type="xsd:unsignedInt" use="optional" default="0"/>  
     <xsd:attribute name="hash" type="xsd:unsignedInt" use="required"/>  

If the text in a textbox is modified, we need to update the hash value of comments in that box, otherwise the comments will be shown related to the box, and not a specific range.

Could you elaborate on how this hash value is calcualted?

Best regards,

Sándor Kolumbán

Office Open Specifications
Office Open Specifications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Open Specifications: Technical documents for protocols, computer languages, standards support, and data portability. The goal with Open Specifications is to help developers open new opportunities to interoperate with Windows, SQL, Office, and SharePoint.
122 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hung-Chun Yu 976 Reputation points Microsoft Employee

    Hi @Sándor Kolumbán

    You can find the Example of Hash under Non-Null-Terminated Unicode String to Unsigned Integer Hash

    Given a non-null-terminated Unicode string and the length of the string, a 4-byte unsigned integer hash value can be obtained by performing the following algorithm:

    1. Given an input string and length of the input string (cch).
    2. Set a 4-byte unsigned integer value nHash equal to 0x00000000.
    3. For each character from position 0 to the end of the input string perform the following steps.


          for (i=0; ich<cch; ++ich)  
             nHash = (nHash<<5) + nHash + inputString[ich];  

    1. Set nHash, equal to itself bitwise shifted left 5 times, added unto itself, and then added to the value of the character of input string at ich.

    1. nHash will be stored and used again in the next iteration of the loop until the last character of input string.
    2. The result of the algorithm is the value nHash.

    Let me know if this helped

    Hung-Chun Yu
    Microsoft Open Specifications Support

    0 comments No comments