|
|
|
Sample code for using RecogniContact/COM address parser in
C++
NOTES
- Replace [YOUR NAME] and [YOUR LICENSE KEY] with your license
details
- In the main application using RecogniContact.dll, set the maximum
stack size to at least 2 megabytes.
#include
#include "stdafx.h"
#include "Objbase.h"
#import "RecogniContact.tlb" no_namespace
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HRESULT hr = CoInitialize(NULL);
VARIANT Value;
wchar_t resultStr[2048] = {0};
wchar_t sourceStr[2048] = {0};
BSTR licDaysStr = {0};
if(FAILED(hr))
{
MessageBox(NULL, "Failed to initialize the COM libraries\n", "RecognicontactDemo", MB_OK);
return FALSE;
}
IContactParser* parser;
IParsedContact* parsedContact;
IParserSettings* parserSettings;
//create the address parser COM object instance
//---------------------------------------------
hr = CoCreateInstance(__uuidof(Parser), 0, CLSCTX_INPROC_SERVER, __uuidof( IContactParser), reinterpret_cast(&parser));
if(FAILED(hr))
{
MessageBox(NULL, "Failed to create COM object\n", "RecognicontactDemo", MB_OK);
CoUninitialize();
return FALSE;
}
//initialize the address parser with your license data
//----------------------------------------------------
parser->Initialize(L"[YOUR NAME]",L"[YOUR LICENSE KEY]");
//show remaining license days in parser license
//---------------------------------------------
licDaysStr = parser->GetLicenseInfo(litDaysLeft);
MessageBoxW(NULL, licDaysStr, L"License days left", MB_OK);
//if licDaysStr="" --> license is unlimited
//================================================
//adjusting the address parser settings (optional)
//================================================
//get the address parser settings object
//--------------------------------------
parserSettings = parser->CreateSettingsObject();
//modify the address parser settings object
//-----------------------------------------
parserSettings->UseCountryFromPlaceName = true;
parserSettings->TranslateExistingCountryNames = true;
parserSettings->CountryNameLanguage = Language_EN;
parserSettings->StandardizePhoneNumberFormat = true;
parserSettings->InternationalPhoneNumber_IntlAccessCode="+";
parserSettings->InternationalPhonePrefixFormat = "_(123)_";
parserSettings->MakeAllPhoneNumbersInternational=true;
parserSettings->MakeAllPhoneNumbersInternational_DefaultCountry=Country_US;
//activate the new address parser settings
//----------------------------------------
parser->Settings(parserSettings);
//set text to parse
//-----------------
wcscat_s(sourceStr, L"Dr. Walter W. Wagoner - Exhibition Manager \n");
wcscat_s(sourceStr, L"The Museum of Modern Art \n");
wcscat_s(sourceStr, L"Address: 11 West 53 Street, New York, NY 10019\n");
wcscat_s(sourceStr, L"Phone: (212) 708-9400\n");
wcscat_s(sourceStr, L"Email: info@moma.org\n");
wcscat_s(sourceStr, L"Web: www.moma.org");
//do the address parsing
//----------------------
parsedContact = parser->Parse(sourceStr);
//show the parsed country
//-----------------------
Value = parsedContact->GetValue(ContactFieldType_Country);
wcscat_s(resultStr,L"Country = ");
if (Value.pbstrVal!=NULL) wcscat_s(resultStr, Value.bstrVal);
MessageBoxW(NULL, resultStr, L"RecognicontactDemo", MB_OK);
/*you can call GetValue() with the following arguments
----------------------------------------------------
ContactFieldType_Prefix
ContactFieldType_FirstName
ContactFieldType_MiddleName
ContactFieldType_LastName
ContactFieldType_Suffix
ContactFieldType_Company
ContactFieldType_Company2
ContactFieldType_Position
ContactFieldType_StreetAddress1
ContactFieldType_StreetAddress2
ContactFieldType_PostboxAddress
ContactFieldType_PostboxPostCode
ContactFieldType_PostCode
ContactFieldType_PlaceName
ContactFieldType_Province
ContactFieldType_Country
ContactFieldType_Phone1
ContactFieldType_Phone2
ContactFieldType_Mobile
ContactFieldType_Fax
ContactFieldType_Email
ContactFieldType_Url
ContactFieldType_Gender
ContactFieldType_CountryIsoCode */
CoUninitialize();
return 0;
}
|