Search code examples
c++visual-c++pointfirebreath

Can't return the POINT to use in another function


Got this code:
(I'm using FireBreath)

TestPluginAPI.h
FB::variant ClickSemulationMove(POINT);
FB::variant ClickSemulationClick(POINT);



TestPluginAPI.cpp

FB::variant TestPluginAPI::ClickSemulationClick(POINT pt)
{
ShowCursor(true);
MouseLeft();
MouseReturn(pt.x, pt.y);
ShowCursor(true);
return 0;
}

FB::variant TestPluginAPI::ClickSemulationMove(POINT &pt)
{
MouseMove(-325, 605);
POINT pt;
GetCursorPos(&pt);
return 0;
} 

The idea is, that firstly goes ClickSemulationMove, saves pt from GetCursorPos (i need exactly this pt, cos i must get it before moving the mouse, to return there then.) and then pass it to ClickSemulationClick to use in MouseReturn.
But i got following errors:
C2511: FB::variant TestPluginAPI::ClickSemulationMove(POINT &) overloaded member function not found in "TestPluginAPI" and error C2665: FB::variant_detail::conversion::convert_variant: none of the 5 overloads can convert all parameter (this error got bunch of some code and parameters below, will post if needed) It sounds pretty simple, but what exactly am i doing wrong?


Solution

  • 2 problems here; the first is that you can't pass arguments by reference into a NPAPI method and thus you can't into a firebreath method either. Second, you can't use just any arbitrary type.

    You have a few options:

    1. For input, I recommend you just pass int x, int y into the function.
    2. For output, you can either pass a string that you decode or a FB::VariantList with the values you need which will become a javascript array. You could also return a FB::VariantMap which would become a javascript object allowing you to pass named x and y values.
    3. If you really want to be able to pass things by reference you could pass in a FB::JSObjectPtr which would need to be a javascript object or array ({} or []) that you have saved in javascript. You could then make changes to it by calling ->SetProperty("x", xval) etc or ->SetProperty(0, xval) if you used an array. You could also call ->Invoke("push", FB::variant_list_of(xval)) to just push onto the array.