Firebreath C ++有些指针理解

时间:2013-05-21 16:59:07

标签: c++ winapi pointers firebreath

我在这里问了一个问题Get mouse screen coordinates on click,得到了一个很好的答案(确认一个),这是Gaurav Raj。 在这个样本中:

bool MirrarOrnaments::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *) 
{
  if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left) 
  {
    /** 
     * apiPtr is the pointer to FB::JSAPIPtr 
     * mousePositionCallback is the JSAPI function which takes variant list of mouse 
     * co-ordinates as argument 
     */ 
    apiPtr->invoke("mousePositionCallback", FB::variant_list_of(evt->m_x)(evt->m_y)); 
  }
}

正如我所知,最后一个字符串必须在我的JavaScript中运行mousePositionCallback函数,参数为FB::variant_list; 但我无法理解apiPtr指针的用途,我在哪里可以得到它以及这个指向FB::JSAPIPtr的指针必须如何实际查看我的代码。

1 个答案:

答案 0 :(得分:1)

FireBreath中的FB :: JSAPIPtr类型只是boost :: shared_ptr(共享自动指针)的便利别名,所以你不必在对象上调用delete,也不必担心它会消失......

尝试添加getRootJSAPI()调用,这应该为您返回apiPtr。

bool MirrarOrnaments::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *) 
{
  if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left) 
  {
    /** 
     * apiPtr is the pointer to FB::JSAPIPtr 
     * mousePositionCallback is the JSAPI function which takes variant list of mouse 
     * co-ordinates as argument 
     */ 
    // if you want to access it from the API Part
    // FB::JSAPIPtr apiPtr(boost::make_shared<FBYourPluginAPI>(m_plugin));
    //add the next line:
    FB::JSAPIPtr apiPtr = m_plugin.lock()->getRootJSAPI();
    apiPtr->Invoke("mousePositionCallback", FB::variant_list_of(evt->m_x)(evt->m_y)); 
  }
}