Bugs with IFormatService GetOutputStyles Api


    Now, I’m trying to use formatting citations function in my plugin, and I found a bug with IFormatServices.GetOutputStyles Api.

the bug is described as follows

  1. I set the style folder in “endnote preferences” to folder “D:\Program Files\EndNote\Styles\Style”, this folder exists and with some own styles in it.

  2. when using endnote, I can find these styles when chosing a output style.

  3. when I using IFormatService GetOutputStyles function to get the whole list of my styles, these styles in  “D:\Program Files\EndNote\Styles\Style” are not in the list.

so this seems to be a bug.

The version of endnote is X4 update 2(updated just now).

Besides, when using codes in Chapter 12. Formatting Citations

these code

IFormatServiceCallback* MyFormatImplementation::CreateInstance( /*params needed for your implementation*/ )
	// Because your implementation is derived from RSService objects that are, in
	// turn, based on reference counting semantics, it is important to properly
	// initialize the underlying reference counting mechanisms. This should be
	// done by allocating the object on the heap and using the CBaseObject
	// template to instantiate your implementation. That template takes care of
	// implementing reference counting, but it means you can only use a
	// default constructor to initialize your class. As such, it is often easiest
	// to use a "create" function that calls CBaseObject<> and inits all member
	// variables requiring external parameters. So CreateInstance() here is just
	// a convenience function to encapsulate CBaseObject<> and member initialization
	// in one place. It's not a required way of doing it, just an easy way of doing
	// it. You can do it in alternate ways, depending on the needs of your code.

	IFormatServiceCallbackPtr p = new CBaseObject< MyFormatImplementation >();

	if (p)
		// init any members using passed-in parameters

	// note that we didn't use a smart pointer above, since that would have
	// freed our newly created object when the function went out of scope.

	return p;

we’ll get an error with visual studio 2008

error C2061: syntax error: identifier “CBaseObject”

how to fix this problem?

function  IFormatService.FormatRecord and IFormatService.FormatRecords needs a param typed as IStringList **, but IFormatCalback ptr was passed in.

this cast from callback to IStringList ** is failed in vs 2008

ServiceErr err = pFormat->FormatRecords( NULL, pList, xml.c_str(), (IString**) pMyCallback );

So, how to deal with this?


ServiceErr err = pFormat->FormatRecords( NULL, pList, xml.c_str(), (IString**)((void*)pMyCallback) );

For the styles you may need to place the custom styles directly in the Styles folder where EndNote X4 was installed.

Unfortunately, this doesn’t work. The err will be kServiceErrGeneric after the call.

Below is my test code.

ITStringListPtr pList;
	IFormatServicePtr pFormat =(IFormatService *)m_pReq->GetService(kFormat);
	ServiceErr err=pFormat->GetOutputStyles(&pList);

	if ((err == kServiceNoErr) && (pList->size()>0))
		ostringstream xml;
		xml << "<format_reflist>";
		xml << "<style>";
		xml << CT2A(pList->item(1));
		xml << "</style>";
		xml << "<starting-refnum>1</starting-refnum>";
		xml << "<progress-message>Sorry for the inconvenience!</progress-message>";
		xml << "</format_reflist>";
		IFormatServiceCallbackPtr format = MyFormatImplementation::CreateInstance();
		IUIServicePtr pUI;
		IUIDatabasePtr pUIDB;
		IRecordListPtr pSelectedRecs;
		if (!m_pReq){
		if (!pUI){
		if((pUI->GetLibrary(pUI->kFrontMost,&pUIDB)) != kServiceNoErr ){
		if((pUIDB->GetRecords(pUIDB->kSelected, &pSelectedRecs)) != kServiceNoErr){
		ServiceErr err=pFormat->FormatRecords(NULL,pSelectedRecs,xml.str().c_str(),(IString **)((void *)format));


the xml I passed to the call is as below

<format_reflist><style>AAG Style Guide.ens</style><starting-refnum>1</starting-refnum><progress-message>Sorry for the inconvenience!</progress-message></format_reflist>

You might want to try:

  1. Removing the progress-message tag form the XML, if you look at the IFormatServiceTest.cpp file in the rsservicestest plugin that came with the RDK you will see that tag was not present.

  2. You may want to check that the MyFormatImplemntation::CreateInstance() call is returning successfully.  It is possible that there is a problem with the callback.

I compiled the RSServicesTest project and run it, about formating records, records as follow

SUCCESS: IUIService::AddToolsMenuItem
SUCCESS: IDatabaseService::Notify
SUCCESS: IDatabaseServiceNotifyCallback::OnDatabaseOpened (C:\Documents and Settings\coolspace\My Documents\My EndNote Library.enl)
SUCCESS: IUIServiceNotifyCallback::OnMenuItemSelected
SUCCESS: IVersion::GetServiceVersion (02.05.13)
SUCCESS: CServiceRequest::GetID (2)
SUCCESS: CServiceRequest::GetService
SUCCESS: CServiceRequest::GetServiceMode (0)
SUCCESS: IDatabase::GetPath (C:\Documents and Settings\coolspace\My Documents\My EndNote Library.enl)
SUCCESS: IDatabase::GetDataDirectory (C:\Documents and Settings\coolspace\My Documents\My EndNote Library.Data)
SUCCESS: IDatabase::GetAccessPermission (0)
SUCCESS: IDatabase::IsTemporary (false)
SUCCESS: IDatabase::GetRecordCount (4)
SUCCESS: IDatabase::GetRecordList (4)
SUCCESS: IDatabase::GetRecNum (1)
SUCCESS: IDatabase::GetRecordID (<RecordID database="1" recNum="1" />)
SUCCESS: IDatabase::ReadRecord (<RecordID database="1" recNum="1" />)
SUCCESS: IDatabaseNotifyCallback::OnRecordChanged ( <RecordID database="1" recNum="1" />)
SUCCESS: IDatabase::WriteRecord
SUCCESS: IDatabase::CreateNewRecord
SUCCESS: IDatabaseNotifyCallback::OnRecordCreated ( <RecordID database="1" recNum="17" />)
SUCCESS: IDatabase::AddRecord (<RecordID database="1" recNum="17" />) (5)
SUCCESS: IDatabaseNotifyCallback::OnRecordDeleted ( <RecordID database="1" recNum="17" />)
SUCCESS: IDatabase::DeleteRecord (4)
SUCCESS: IDatabase::ImportRecords (5)
SUCCESS: IDatabase::DeleteRecords (4)
SUCCESS: IDatabase::CommitChanges (true)
SUCCESS: IDatabase::GetReferenceTypes (50)
SUCCESS: IDatabase::GetUIAccess (4)
SUCCESS: IDatabase::Search (0)
SUCCESS: IDatabase::TransferRecords (1)
SUCCESS: IDatabase::GetForeignKeys
SUCCESS: IDatabase::SetForeignKeys
SUCCESS: IDatabase::GetGroups (1)
SUCCESS: IDatabase::GetProperty (zx2a92spvzevzze5vvnxv2w1x90s50s2w9fz)
FAILURE: IDatabase::SetProperty 23008 (Internal, error expected)
SUCCESS: IDatabase::GetTrash (0)
SUCCESS: IDatabase::PutInTrash (1)
SUCCESS: IDatabase::SalvageTrash (0)
SUCCESS: IDatabase::GetFindFullText (15)
SUCCESS: IDatabase::Close
SUCCESS: IDatabaseList::GetCount (2)
SUCCESS: IDatabaseList::GetDatabase (4)
SUCCESS: IDatabaseList::RemoveDatabase (1)
SUCCESS: IDatabaseList::AddDatabase (2)
SUCCESS: IDatabaseList::DatabaseFromRecordID (4)
SUCCESS: IDatabaseList::NewRecordList (0)
SUCCESS: IDatabaseList::GetSearchFields (59)
SUCCESS: IDatabaseList::Search (0)
SUCCESS: IDatabaseService::GetOpenDatabases (2)
SUCCESS: IDatabaseService::GetDataDirectory (C:\Documents and Settings\coolspace\My Documents\My EndNote Library.Data)
SUCCESS: IDatabaseService::NotifyDb
SUCCESS: IDatabaseService::Open (4)
SUCCESS: IDatabaseService::OpenWithProgress (4)
SUCCESS: IDatabaseService::GetRecNum (2) <RecordID database="1" recNum="2" />
SUCCESS: IDatabaseService::Create (C:\idbservice.enl)
SUCCESS: IDatabaseNotifyCallback::OnDatabaseClosed
SUCCESS: IDatabaseServiceNotifyCallback::OnDatabaseClosed (C:\idbservice.enl)
FAILURE: IDatabaseService::LockService (Not Implemented in EndNote)
FAILURE: IDatabaseService::UnlockService 23004 (Not Implemented in EndNote)
SUCCESS: IDatabaseService::NewDatabaseList (0)
FAILURE: IDatabaseService::GetActiveDatabase 23000 (Not Implemented in EndNote)
SUCCESS: IDatabaseService::GetUserDatabases (1)
SUCCESS: IDatabaseService::OpenByDatabaseID (4)
SUCCESS: IRecord::GetDatabase (4)
SUCCESS: IRecord::GetRecordID (<RecordID database="1" recNum="2" />)
SUCCESS: IRecord::GetXML (1327)
SUCCESS: IRecordList::GetCount (4)
SUCCESS: IRecordList::GetRecordID (<RecordID database="1" recNum="2" />)
SUCCESS: IRecordList::AddRecord
SUCCESS: IRecordList::GetDatabase (4)
SUCCESS: IRecordList::Sort
SUCCESS: IRecordList::GetSubset (1)
FAILURE: IRecordList::GetMetaData 23008 (Internal, error expected)
SUCCESS: IRecordList::AddRecordList (4)
SUCCESS: IRecordList::Clear (0)
SUCCESS: IRecordList::Copy (4)
SUCCESS: IRecordList::Exclude (0)
SUCCESS: IRecordList::Or (4)
SUCCESS: IRecordList::And (4)
SUCCESS: IRecordList::RemoveRecord (3)
SUCCESS: IRecordList::RemoveRecordList (0)
FAILURE: IRecordList::GetRecordIDRange 23004 (Not Implemented in 2.5.12 and below)
UNKNOWN: IProgress::BeginProgress
SUCCESS: IProgress::IncrementProgress
SUCCESS: IProgress::UpdateProgress
SUCCESS: IProgress::CheckProgress (Continue)
UNKNOWN: IProgress::EndProgress
UNKNOWN: IProgress::BeginProgressNoCancel
SUCCESS: IReferenceTypes::Count (50)
SUCCESS: IReferenceTypes::FromID
SUCCESS: IReferenceTypes::FromName (Journal Article)
SUCCESS: IReferenceTypes::FromIndex
SUCCESS: IReferenceType::GetName (Journal Article)
SUCCESS: IReferenceType::GetID (17)
SUCCESS: IReferenceType::FieldInReferenceType (1)
SUCCESS: IReferenceType::FirstOrderedField (4)
SUCCESS: IReferenceType::NextOrderedField (41)
SUCCESS: IReferenceType::GetFieldName (Author)<font color="#ff0000">SUCCESS: IFormatService::GetOutputStyles (158)
SUCCESS: IFormatService::FormatRecord
SUCCESS: IFormatService::FormatRecordIDs
FAILURE: IFormatService::FormatRecords 23000
FAILURE: IFormatService::FormatManuscript 23000</font>SUCCESS: IString::assign
SUCCESS: IString::c_str (OK)
SUCCESS: IString::length (2)
SUCCESS: IStringList::push_back
SUCCESS: IStringList::size (1)
SUCCESS: IStringList::item (String 1)
SUCCESS: IWideString::assign
SUCCESS: IWideString::c_str (OK)
SUCCESS: IWideString::length (2)
SUCCESS: IWideStringList::push_back
SUCCESS: IWideStringList::size (1)
SUCCESS: IWideStringList::item (String 1)
SUCCESS: IUIDatabase::GetDatabase (4)
SUCCESS: IUIDatabase::GetRecords (4)
SUCCESS: IUIDatabase::Display (4)
SUCCESS: IUIDatabase::DisplayAsGroup (RSServices DisplayAsGroup)
SUCCESS: IUIDatabase::Refresh
SUCCESS: IUIDatabase::PostGroup (RSServices PostGroup)
SUCCESS: IUIDatabase::PostSmartGroup (RSServices PostSmartGroup)
SUCCESS: IUIDatabase::PostAutoGroup (RSServices PostAutoGroup)
SUCCESS: IUIDatabase::DeleteAutoGroup (RSServices PostGroup)
SUCCESS: IUIDatabase::GetGroupPanelSortOrder (0)
SUCCESS: IUIDatabase::PostAutoGroupWithIconRules (RSServices PostAutoGroupWithIconRules)
SUCCESS: IUIDatabase::CloseDatabase
UNKNOWN: IUIService::LockUI (1) (Not Implemented in EndNote)
UNKNOWN: IUIService::AnimateLock
FAILURE: IUIService::UnlockUI 23004 (Not Implemented in EndNote)
UNKNOWN: IUIService::ProcessEvents
SUCCESS: IUIService::GetLibrary
SUCCESS: IUIService::RegisterGroupSetCallback
SUCCESS: IUIService::OpenDatabase
SUCCESS: ICitationService::EmptyCitationList
FAILURE: ICitationService::CitationFromRecordXML 23004 (Not Implemented in 2.5.12 and below)
FAILURE: ICitationService::CitationFromCitationXML 23004 (Not Implemented in 2.5.12 and below)
SUCCESS: ICitationService::ParseTemporaryCitation
SUCCESS: ITempCitation::GetCount
SUCCESS: ITempCitation::IsGroupedCitation
SUCCESS: ITempCitation::ExtractCitation
SUCCESS: ICitationList::IsEmpty (true)
SUCCESS: ICitationList::GetCount (0)
SUCCESS: ICitationList::AddCitation (1)
SUCCESS: ICitationList::RemoveCitation (0)
SUCCESS: ICitationList::InsertCitation (1)
SUCCESS: ICitationList::GetCitation
SUCCESS: ICitationList::GetFormatterXML (134)
SUCCESS: ICitation::IsNote (false)
SUCCESS: ICitation::IsFootnote (false)
SUCCESS: ICitation::IsContiguous (false)
SUCCESS: ICitation::SetContiguous (true)
SUCCESS: ICitation::SetFootnote (true)
UNKNOWN: ICitation::SetNoteNumber
SUCCESS: ICitation::IsAuthorExcluded (false)
SUCCESS: ICitation::IsDateExcluded (false)
SUCCESS: ICitation::GetNote ()
SUCCESS: ICitation::GetYear (1987)
SUCCESS: ICitation::GetAuthor (Billoski)
SUCCESS: ICitation::GetIdentifyingText ()
SUCCESS: ICitation::GetPrefix (prefix)
SUCCESS: ICitation::GetSuffix (suffix)
SUCCESS: ICitation::GetPages (pages)
SUCCESS: ICitation::GetRecordIdentifier (16)
SUCCESS: ICitation::GetTempCitationText (prefix\Billoski, 1987 #16suffix@pages)
SUCCESS: ICitation::IsResolved (false)
SUCCESS: ICitation::Match (0)
FAILURE: IRecordList::GetRecordID 23000
FAILURE: ICitation::GetCitationXML 23004 (Not Implemented in 2.5.12 and below)

So, from ubove results, we can found, even using the RSServicesTest project in the RDK, the function formatrecords also returns 23000 error. And after reading the codes, I found that we should have outputs like

"SUCCESS: IFormatServiceCallback::OnBeginRecord\n"


but unfortunately we cann’t find them, so these also mean that any functions like onBeginRecord, onEndRecord,OnFormatText were not called. 

I don’t know why this happens.

Have you work out why the demo project RSServicesTest also doesn’t work?

I’m waiting for solving this problem


I just ran RSServicesTest and, sure enough, FormatRecords appears to be failing on this end, too.  However, I’m able to get it to work, by fixing the following item in the test code:

const char* szFormatSpec = "<format_reflist><style>Numbered</style> …

Once I remove the “.ens” from the style name, the test succeeds.  The test code and yours is mostly modeled after the sample in Chapter 12, which also has the ‘.ens’ extension in the name.  If you remove the ‘.ens’ within this line of code:

xml << CT2A(pList->item(1));

does that fix the problem?

As an aside, you can see that the RSServicesTest code for FormatManuscript doesn’t use the .ens for its <output-style> node, which is consistent with the documentation on pp. 281 & 282 for that node.  On my side, the FormatManuscript node passes the test, so I suspect in that particular case you might just not have the Annotated style in your set of styles, as that’s the one that particular test relies upon.

Let me know if the .ens change resolves your problem.  Hope this helps!

Thank you for your help.


All formatServices related functions have this problem.  The events of FormatSeviceCallback was not called.

Such as  FormatManuscript,  FormatRecord,  FormatRecordIDs and  FormatRecords.

Take the RSServicesTest project that came from the RDK samples for example.

Default, all format functions in RSServicesTest are failed.

And you can find a note “//TODO: verify this is working, I suspect it is not since the CBs are not called” in the IFormatServiceTest.cpp. This means that the guy who wrote this sample also find this problem.

After changing the “Numbered.ens” to “Numbered” as you said.

FormatRecords function seems to work correctly.

But other functions, FormatRecord, FormatRecordIDs and FormatManuscript remain don’t work.

All above results are taken from the RSServicesTest project. And I think you can also test them yourself.

I’m still waiting for the solutions to these problems.

“But other functions, FormatRecord, FormatRecordIDs and FormatManuscript remain don’t work.”

FormatRecord and FormatRecordIDs are actually deprecated v2.0 functions.  EndNote doesn’t support them anymore, which also reflects the “TODO” comment you noticed: the author of the test script wasn’t aware of that when that test was first coded, but the comment was never removed.

Since it sounds like the ‘.ens’ change is working for FormatRecords, that leaves only the issue with FormatManuscript.  FormatManuscript is actually used in live production code, and it works when I run RSServicesTests on all the machines I try here.  So I suspect that it might just be a problem in the test parameters that aren’t consistent with your environment.

The simplest problem would be that the style being used in the FormatManuscript XML is not available in your environment.  If you change the definition of ‘szManuscriptFormatSpec’ in IFormatServiceTest.cpp to a different style, e.g. ‘Numbered’, does it work?  Note that I suggest ‘Numbered’ only because it sounds like that worked for your FormatRecords test, so I’m assuming that one is definitely available in your style folder.


OK, I got it, now I’m using FormatRecords api in my plugin, and it works well.

BTW : It seems that the documents should be improved, as lots of changes can’t be found in the documents or the RSSVersion.h

Such as FormatRecord api, for my situation, this api is much more convenient than FormatRecords as I deal with only one record at a time, so I don’t need to create a new RecordList ptr.