c++ - Firebreath C++一些指针的理解

标签 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 中使用 FB::variant_list 参数运行 mousePositionCallback 函数; 但是我无法理解 apiPtr 指针的用途,我在哪里可以得到它以及这个指向 FB::JSAPIPtr 的指针实际上必须如何在我的代码中查找。

最佳答案

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)); 
  }
}

关于c++ - Firebreath C++一些指针的理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16675509/

相关文章:

c++ - 创建不带 PIPE_REJECT_REMOTE_CLIENTS 的NamedPipe

删除动态表时出现 C++ 段错误

c++ - 重载函数和继承

c++ - 下面的代码在c++中是什么意思?

c# - 以给定备用安全身份凭证的用户身份登录

c++ - 从证书中获取 "Key Usage"

c++ - 通过范围循环从指针容器中获取取消引用元素的引用

c++ - C++ 复制构造函数上的双重释放错误

c++ - #define a b+c 混淆..我没有得到我预期的输出

c++ - 停止在 C 中刷新 io 缓冲区