Search code examples
winapinpapifirebreath

Callback using CustomWndProc for Message Only Window Handle


I am developing a NPAPI plugin using firebreath. I am using a third party dll to integrate to a gaming device.The inputs on the devices are propagated to the plugin through a message only window(HWND) registered while opening a channel to the device.

Initially, handshake with the device driver, handshake(HWND,...) and after which on user input, a callback is made on CustomWinProc() to notify.

I did the following,

-Created an Header&CPP file under the WIN-CustomCallbackHandler.h ,

   #include "Win\PluginWindowWin.h"
   #include "Win\WindowContextWin.h"

    class CustomCallbackHandler : public FB::PluginWindowWin
     {
       public:
     CustomCallbackHandler (const FB::WindowContextWin& ctx);

      protected:
     virtual bool CustomWinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM   
        lParamm,LRESULT & lRes);
     };

-CustomCallbackHandler.cpp

    [code]
    #include "CustomCallbackHandler.h"
    #include "PluginWindowForwardDecl.h"
    #include "Win\WindowContextWin.h"
    #include "Win\PluginWindowWin.h"

    CustomCallbackHandler::CustomCallbackHandler(const FB::WindowContextWin& ctx) :    
    FB::PluginWindowWin(ctx){
    }

    bool CustomCallbackHandler::CustomWinProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM 
    lParamm,LRESULT & lRes){
    //if WPARAM is something some operation has to be performed.
 return false;
    }
    [/code]

-Factory.cpp - Added the following method to override the PluginWindowWin

FB::PluginWindowWin* createPluginWindowWin(const FB::WindowContextWin& ctx)
{
    return new CustomCallbackHandler(ctx);

}

-MyFirstPluginAPI.cpp-(The auto generated JSAPIAuto subclass)- JS method.

    bool MyFirstPluginAPI::handshake(FB::JSObjectPtr &callback)
     {
        FB::WinMessageWindow window;
        thirdpartymethod(window.getHWND());
     }

Now,When I debug I could see the customcallbackhandler being invoked a couple of times for the regular plugin events but the events generated by the devices are not available.I believe a different instance of message window is passed on to the dll.

-How do I get the handle of the PluginWindowWin?
-Once I receive a callback on the CustomCallbackHandler,How do I generate a custom sendEvent()?

Your help is highly appreciated.

I am a Java developer and don't have much experience in C++ programming. I believe I am missing something fundamental.


Solution

  • What you want is to use WinMessageWindow:

    https://github.com/firebreath/FireBreath/blob/master/src/PluginCore/Win/WinMessageWindow.h

    You don't want to use PluginWindowWin; that's too specific for other things. WinMessageWindow was created specifically to do the types of things you are trying to do, and it allows you to make a winproc handler on the containing class.

    I recently posted an example of using WinMessageWindow in order to receive WM_DEVICENOTIFY messages; I'm sure you can use it as an example of how the class works to get you started.