1

I am working with the C++ API for ArcObjects (Linux, QT), and I am running into problems with when creating a custom button on a toolbar. I have read up on the C++ specific implementation of creating a custom command (inheriting from AoCommandBase and adding the button with AoToolbarAddCommand).

After many hours of fiddling around, I have come to the conclusion that AoToolbarAddCommand simply isn't doing its job. I can add ESRI predefined commands with no problem, but my custom command shows up as a useless grey square (my icon doesn't even display). My debug output suggests that none of the functions defined in my command are being called during setup (or ever for that matter), and they definitely should be. If it helps, excerpts from my code are below:

From the add_toolbar_items function:

CComVariant varTool;

long itemindex;

varTool = L"esriControlCommands.ControlsOpenDocCommand";
ipToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);

panRight = new PanRight(); /*panRight is global, PanRight is my command class*/

AoToolbarAddCommand(ipToolbar, panRight, esriCommandStyleIconOnly);

The PanRight class (my custom button) is stolen from a sample, but I changed the code for loading bitmaps because the provided code did not work. All the other functions remain unchanged, except for a cout statement letting me know if the function were ever to run.

PanRight::PanRight()
{
  m_ipHookHelper.CrreateInstance(CLSID_HookHelper);
  std::cout<<"panright constructor\n";

  //load bitmap
  IPictureElement3Ptr ipPict(CLSID_PictureElement);
  HRESULT hr = ipPict->ImportPictureFromFile(CComBSTR(L"<pathToPic>"));
  if(SUCCEEDED(hr))
  {
    OLE_HANDLE hBitmap;
    hr = ipPict->get_Handle(&hBitmap);
    if(SUCCEEDED(hr))
      {m_hBitmap = hBitmap;}
  }
}

Does anyone have any ideas as to why AoToolbarAddCommand might not be doing its job? Has anyone successfully added a custom command using the C++ API?

2
  • Did you get the sample working here that adds a custom date tool? See add_toolbar_items function. Jul 2, 2013 at 15:29
  • No - I was able to run the sample, but the custom toolbar item they added did not show up, except for a useless grey square. I confirmed that this sample has the same problem that my program does, none of the functions (get_Bitmap, etc) defined in the custom command are being called.
    – dykeag
    Jul 2, 2013 at 16:16

1 Answer 1

0

As it turns out, this is a known bug in ArcObjects 10.1. ESRI has published a fix in Service Pack 1, but unfortunately this is not available for Linux C++ developers at this time. Hopefully ESRI will publish SP1 for Linux C++ soon, as this toolbar is a requirement for my project!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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