Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an ATL object (CMyCombo) which implements ICommand and IToolControl which contains a combobox on a toolbar.Its default interface is defined as

__interface IMyCombo { STDMETHOD(GetCurrentSelection(UINT* selectedIndex); }

I want to find selected index of this combo box when I click on another command in same toolbar.I can find my ATL object using ICommandBars.Find method as a ICommandItem pointer,but when QI this pointer passing IMyCombo IID,it returns E_NOINTERFACE error,and if I use static_cast I can convert this pointer to CMyCombo* and I can see all local variables of this class but if I want to call GetCurrentSelection I receive another error.

may you help me to find how can I access this method inside my ATL object from another command? Thanks in advance

share|improve this question
up vote 2 down vote accepted

I am not sure if I understand your problem correctly, but here's my two cents. ICommandItem is just a "reference" to your actual command, so you cannot QI it for a custom interface your command implements. In fact, command items do not always need to be tied to a command, as is the case for buttons which fire VBA code, for example.

You can get a reference to your command object via ICommandItem.Command and then cast it to IMyCombo. This property is marked as hidden in the IDL.

share|improve this answer
Thank you petr,as you suggested I used get_Command method of ICommandItem,and then a simple cast worked well. – Reza Dec 21 '10 at 15:19

I have done this in C#. I dont know if the event model is the same in ATL but I implemented IExtension and used it to publish a custom event. Your ICommands can get a reference to your extension in OnCreate using IApplication.FindExtensionByName(). When the combo index changes, the ICommand asks the IExtension to notify any subscribers of the fact. Any other ICommands you have can listen for that event.

share|improve this answer
Thanks for reply,but my another problem is how I can send notification message of this combo box control to its parent.It seems it parents is the toolbar which contains it but i don't know how to send combobox notification messages to this toolbar. – Reza Dec 21 '10 at 15:15
@Reza: the solution described by nef001 is a valid way to go. The idea is to have a central place where to share state, trigger notifications and subscribe to them. Application extensions implementing IExtension are (at least for ArcGis Desktop apps like ArcMap) ideal for this since they can be reached from just about any component (command, toolbar etc.). – Petr Krebs Dec 21 '10 at 16:56
That said, +1 from me – Petr Krebs Dec 21 '10 at 17:22
Right,I have some experineces about extentions in ArcGIS,but the problem is I don't know how dispatch notification messages of my control.It's a combobox which has been created using ::CreateWindow method(Windows API) and I don't know how I can tie its event handlers to other parts of my code in VC++ ATL project.You have any idea how?or may you refer me to a rich resource please? – Reza Dec 22 '10 at 9:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.