Converting DMS to decimal degrees
DMStoDD.cpp
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 


#include <stdio.h>
#include <ArcSDK.h>
#include <olb/esridefensesolutions.h>

#if defined(ESRI_UNIX)
    // implemented in libDefenseSolutionsSDK.so
    void DsInitialize();
#endif


int main (int argc, char **argv)
{
    USES_CONVERSION;

    ::AoInitialize (NULL);

#if defined(ESRI_UNIX)
    ::DsInitialize();
#endif
    {
        IAoInitializePtr ipInit (CLSID_AoInitialize);
        esriLicenseStatus status;
        ipInit->Initialize (esriLicenseProductCodeEngine, &status);
        if ( status != esriLicenseCheckedOut )
        {
            printf ("Invalid Licensing.\n");
            ::AoUninitialize();
            AoExit (0);
        }
    }

    // input a geolocation as DMS string, get back and displace normalized DMS string, DD string, and binary DD
    ICoordinatePtr  ipCoordDMS       (CLSID_DMSCoordinate);
    ICoordinatePtr  ipCoordDD        (CLSID_DDCoordinate);
    const char     *dmsInputString   ("37 -123 32 34.43");
    CComBSTR        normalizedString;
    double          x, y;

    // put a string value in the converter
    ipCoordDMS->put_String (CComBSTR(dmsInputString));

    // get back the normalized DMS string
    ipCoordDMS->get_String (&normalizedString);
    printf ("input = '%s', DMS normalized string = '%s'\n", dmsInputString, OLE2A(normalizedString));

    // now convert DMS coordinates to decimal degrees
    // put the Point property from the DMS coordinate into the DD coordinate
    // the Point property is "common ground" for all Coordinate objects
    IPointPtr ipPoint;
    ipCoordDMS->get_Point (&ipPoint);
    ipCoordDD->put_Point (ipPoint);

    // get back the normalized string and floating-point coordinates
    normalizedString.Empty();
    ipCoordDD->get_String (&normalizedString);
    ipCoordDD->GetCoords (&x, &y);
    printf ("DD normalized string = '%s', binary DD = (%f, %f)\n", OLE2A(normalizedString), x, y);

    return 0;

    // results:
    // input = '37 -123 32 34.43', DMS normalized string = '37 00 00.00N 123 32 34.43W'
    // DD normalized string = '37.00N 123.54W', binary DD = (-123.542897, 37.000000)
}