title: Parsing a Text File To Extract a String
body: <p>I'm parsing a txt file in which I've placed Templates (GUID's) to help identify chunks of data...I'm having trouble parsing STRING variables in the file. While parsing I am using a DataPtr object which iterates by the size of the data type...The problem is that I am not able to calculate the size of a string correctly in order to(after reading the string) move on to the next data type. Here is an example file to be parsed:</p>
  
  <pre><code>xof 0303txt 0032
  
  template Effect {
    &lt;C7D92586-6C57-42d3-8F03-0BDF87EC1848&gt;
    STRING filename;
  }
  
  template Light {
    &lt;ADA248C7-97E3-4a42-A4C1-74EE8536FF37&gt;
    DWORD type;
    array float position[3];
    array float direction[3];
    array float ambient[4];
    array float diffuse[4];
    array float specular[4];
    float power;
  }
  
  template Object {
    &lt;B6494248-7D84-42d3-A4AA-0747E22E08D3&gt;
    DWORD type;  
    array float position[3];
    array float orientation[4];
    STRING name;
    STRING filename;
  }
  
  Effect {
      ".//Data/Scene/TrainingRoom/Effects/effect.fx";
  }
  
  Light {
      1;
      -3.0; 1.0; -3.0;
      3.0; -1.0; 3.0;
      1.0; 1.0; 1.0; 1.0;
      1.0; 0.0; 0.0; 0.0;
      1.0; 1.0; 1.0; 1.0;
      0.1;
  }
  
  Object {
      1;
      0.0; 0.0; 0.0;
      0.0; 0.0; 0.0; 1.0;
      ".//Data/Scene/TrainingRoom/TrainingRoom.x";
  }
  </code></pre>
  
  <p>Here is an example of code which is currently working(w/o string tag):</p>
  
  <pre><code>if(CompareDataObjectType(pDataObj, TID_D3DRMLightCustom))
      {
          D3DXVECTOR3 *vecPtr = NULL;
          D3DXVECTOR4 *colorPtr = NULL;
          DWORD *DataPtr = (DWORD*)GetObjectData(pDataObj); // Data Pointer points at 1st data location
          m_light.type = *DataPtr++;  
          vecPtr = (D3DXVECTOR3*)DataPtr;
          m_light.position = *vecPtr;
          DataPtr+=3; 
          vecPtr = (D3DXVECTOR3*)DataPtr;
          m_light.direction = *vecPtr;
          DataPtr+=3;
          colorPtr = (D3DXVECTOR4*)DataPtr;
          m_light.ambient = *colorPtr;
          DataPtr+=4;
          colorPtr = (D3DXVECTOR4*)DataPtr;
          m_light.diffuse = *colorPtr;
          DataPtr+=4;
          colorPtr = (D3DXVECTOR4*)DataPtr;
          m_light.specular = *colorPtr;
          DataPtr+=4;
          float *fPtr = (float*)DataPtr;
          m_light.power = *fPtr;
          return true;
      }
  </code></pre>
  
  <p>This is all okay...The following returns incorrect results:</p>
  
  <pre><code>if(CompareDataObjectType(pDataObj, TID_D3DRMObject))
      {
          D3DXVECTOR3 *vecPtr = NULL;
          D3DXQUATERNION *quatPtr = NULL;
          DWORD *DataPtr = (DWORD*)GetObjectData(pDataObj);       
          m_object.type = *DataPtr++; 
          vecPtr = (D3DXVECTOR3*)DataPtr;
          m_object.position = *vecPtr;
          DataPtr+=3;     
          quatPtr = (D3DXQUATERNION*)DataPtr;
          m_object.orientation = *quatPtr;
          DataPtr+=4;
          m_object.name = (LPCSTR)DataPtr;
          size_t length = strlen(m_object.name);
          DataPtr+=length;
          m_object.filename = (LPCSTR)DataPtr; // filename only contains a portion of the correct string...
          return true;
      }
  </code></pre>