Creating a plugin with MinGW

2008-09-30
2012-11-14
  • Seppo Raisanen

    Seppo Raisanen - 2008-09-30

    Hi

    I am trying to create a plugin with MinGW compiler. Currently I have got so far that N++ does load my plugin, but plugin context menu does not contain any text I try to set there and I don't have any idea how to proceed.

    Relevant parts of the code below, full sources and compiled dll available here:
    http://zepi.kapsi.fi/TestPlugin.zip

    const int nbFunc = 2;
    FuncItem funcItem[nbFunc];

    BOOL APIENTRY DllMain( HANDLE hModule,
                           DWORD  reasonForCall,
                           LPVOID lpReserved )
        {
        switch (reasonForCall)
            {
            case DLL_PROCESS_ATTACH:
                funcItem[0]._pFunc = Func1;
                funcItem[1]._pFunc = Func2;
                strcpy(funcItem[0]._itemName, "Test 1");
                strcpy(funcItem[1]._itemName, "Test 2");
                funcItem[0]._pShKey = NULL;
                funcItem[1]._pShKey = NULL;
                break;
            }
        return TRUE;
        }

    extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *nbF)
        {
        *nbF = nbFunc;
        return funcItem;
        }

    It seems that I do set all of the required fields and provide them when asked, but "Plugins->TestPlugin" menu is empty (actually it contains few lines, no text)

    In compiling I use following command:
    g++ -c -o TestPlugin.o TestPlugin.cpp -DBUILD_DLL

    Linking DLL for N++ in MinGW seems to be tricky, currently I use following command:
    g++ -o TestPlugin.dll -Wl -shared -lshlwapi TestPlugin.o
    This seems to be okay for N++, because it won't complain about non-multithreaded DLL (will do that, if I use the "-export-dynamic" argument that example suggest)

    I think there might be something wrong when linking... Any ideas?

     
    • Seppo Raisanen

      Seppo Raisanen - 2008-10-01

      I tried redefining that APIENTRY, didn't help.
      But I got around this problem just by initializing that funcItems when I declared it.

      So managed to create small plugin then: alt-up changes to previous file and alt-down to next one :)

       
    • Seppo Raisanen

      Seppo Raisanen - 2008-10-01

      Well, found the reason...
      DllMain does not get called.

      If I have code like this:
      BOOL APIENTRY DllMain( HANDLE hModule,
                             DWORD  reasonForCall,
                             LPVOID lpReserved )
          {
          ::MessageBox(NULL, "DllMain", "", MB_OK);
          }

      I'll never see that message box.

      Any ideas why this happens?

       
    • Harry

      Harry - 2008-10-01

      I had this with MinGW and TextFX, I believe APIENTRY isn't correctly defined. You may want to manually define it, for example something like
      #define APIENTRY __stdcall
      though that's for the VS compiler, not sure how MinGW likes that.

      Also, you could try to initialize funcItems inside getFuncsArray()

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks