Process selected message(s) from Addin Menu (C API)

Hello all, I’m trying to write a plug-in that can do some processing to the currently selected message(s). My understanding was that for a plug-in to know anything about the UI and current selections I would have to use a menu addin, and I actually thought this would be pretty simple. I can’t get it working though, so I’m hoping someone can point me in the right direction.

I registered my addin and then when the entry is clicked I grab the NAM_COMMAND_INFO, pull out the NAM_CONTEXT_DATA, and grab its VIEWIXDATA. From the VIEWIXDATA structure, I then grab the hSelectedList and hNoteFile and use them with the IDScan function to try to get the list of selected note IDs. Things generally look ok (e.g. I get a valid DB handle), but regardless of what I have selected, IDScan only returns a note ID once, and it’s always the same value. Moreover, if I try to actually get a handle for the note (using NSFNoteOpen with the db handle and the note id) I get an error saying there is no such note.

Am I misunderstanding how to obtain the current selection, or what the hSelectedList is used for? I’m quite perplexed.

In the interest of full disclosure, I should mention that I’m actually using Delphi to create my plug-in, not C. I’ve used Delphi before for extension manager plug-ins, so I’m fairly comfortable with using Delphi to make the API calls, and I don’t think this problem is a result of that. In particular, I know that byte alignment is a concern, especially since the NAM_CONTEXT_DATA structure uses bit fields and a union, but I’ve done some sanity checks and feel pretty confident that I have the correct data in the VIEWIXDATA. For example, the DB handle seems to be correct and the reserved fields are all 0.

Thanks for any help,

Schuyler

Subject: Process selected message(s) from Addin Menu (C API)

I have done this many times. Here is a snippet of some C++ code from a working code sample (and I agree that using Delphi should probably not be a problem):

viewData_ = &(pInfo->Data.IXData.View);

if (viewData_->hNoteFile == NULLHANDLE)

return;

hSelectedList = viewData_->hSelectedList;

if (hSelectedList == NULLHANDLE)

return;

hDB = viewData_->hNoteFile;

notes_scanned = 0L;

while(IDScan(hSelectedList, (FLAG)(notes_scanned++==0L), &note_id))

{

/* Open the selected document */

sError = NSFNoteOpen (hDB, note_id, 0, &hNote);

if (sError != NOERROR)

  return;

Subject: RE: Process selected message(s) from Addin Menu (C API)

Ben, thanks as always for the response. Perhaps it was the fact that you have this working that made me check the code for the umpteenth time, and sure enough I had everything correct except that I was passing hDB to IDScan instead of hSelectedList. Grr.

I feel like an idiot and want my day back, but it works like a champ.

Thanks again,

Schuyler