Q:

Can't convert geometry from Dgn file to shapefile?

I am using below codes to try convert geometry from a Dgn file to shapefile. But, I can't exit the Feature reading loop. 
Does anyone know why and how to fix it? 
Please download the .dgn file from the link: DgnFile
bool Convert()
{
    OGRRegisterAll();
    OGRDataSource       *poDS,  *poSHPDS;
    const char *pszDriverName = "ESRI Shapefile";
    OGRSFDriver *poDriver;
    poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
                  pszDriverName );

    // Open file DGN
    poDS = OGRSFDriverRegistrar::Open( sourceFile, FALSE );

    if( poDS == NULL )

    {
         cout << "Error opeing DGN file." << endl;
         return false;
    } 
    // Create datasource for file shp
  poSHPDS = poDriver->CreateDataSource(destinationPath,NULL);

  if( poSHPDS == NULL )
  {
        cout << "Error creating shape file." << endl;
        return false;
  }     
  OGRLayer  *poLayer, *poSHPLayer; 

  // Get Layer from DGN file

  poLayer = poDS->GetLayer(0);

  // Create new Layer of SHP file

  poSHPLayer = poSHPDS->CreateLayer (shpFileName, NULL, wkbPolygon, NULL);

  if(poSHPLayer == NULL)

  {

          cout << "Error creating Layer of Shape File." << endl;

          return false;
  }

  OGRFeature *poFeature;

  poLayer->ResetReading(); 

  **while( (poFeature = poLayer->GetNextFeature()) != NULL ) // Can't exit this loop** 

  {

        OGRGeometry *poGeometry;
        poGeometry = poFeature->GetGeometryRef();

        // if feature is a Polygon
        if( poGeometry != NULL && (wkbFlatten(poGeometry->getGeometryType()) == wkbPolygon ) )
        {
                OGRFeature *poSHPFeature;
                //Create new Feature shape file
                poSHPFeature = OGRFeature::CreateFeature (poSHPLayer->GetLayerDefn());
                poSHPFeature->SetGeometry (poGeometry);
                OGRPolygon *poPolygon = (OGRPolygon*) poSHPFeature->GetGeometryRef();

                poLayer->SetSpatialFilter(poGeometry);
                poLayer->ResetReading ();

         }
         OGRFeature::DestroyFeature( poFeature );

    }
    OGRDataSource::DestroyDataSource( poDS );
    OGRDataSource::DestroyDataSource( poSHPDS );
    return true;
} 

A:

The ResetReading() call inside the loop is "taking you back to the start" on each iteration. You'll need to remove the 
poLayer->ResetReading ();

line to continue iterating over the layer features.

