Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Plugin Extensions

Plugin Extensions

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialdotnetquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laphijia
    wrote on last edited by
    #1

    I was wondering what are the principles of creating a plugin extendable program. I mean a program that accepts custom functions being created by third party developer, following certain rules. Like Winamp, or Windows Media Player, that with plus has the Speaker Enanchement pluging: you install the plugin and there is a new Item in the Windows Media menu. Is there any tutorial, guide, etc about this? Thank you. "Nelle cose del mondo non e' il sapere ma il volere che puo'."

    T C 2 Replies Last reply
    0
    • L laphijia

      I was wondering what are the principles of creating a plugin extendable program. I mean a program that accepts custom functions being created by third party developer, following certain rules. Like Winamp, or Windows Media Player, that with plus has the Speaker Enanchement pluging: you install the plugin and there is a new Item in the Windows Media menu. Is there any tutorial, guide, etc about this? Thank you. "Nelle cose del mondo non e' il sapere ma il volere che puo'."

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      You may find some ideas here: http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0797/snapins.htm[^] Tomasz Sowinski -- http://www.shooltz.com

      - It's for protection
      - Protection from what? Zee Germans?

      1 Reply Last reply
      0
      • L laphijia

        I was wondering what are the principles of creating a plugin extendable program. I mean a program that accepts custom functions being created by third party developer, following certain rules. Like Winamp, or Windows Media Player, that with plus has the Speaker Enanchement pluging: you install the plugin and there is a new Item in the Windows Media menu. Is there any tutorial, guide, etc about this? Thank you. "Nelle cose del mondo non e' il sapere ma il volere che puo'."

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        for the plugin system i use, i simply came up with a COM interface for the plugins and just told people that if they want to write a plugin for my apps they must: create an ATL object with this interface, name the object thusly, and place it in this folder. at runtime, my app scans that folder and finds all the DLLs there. then it does a CreateObject call on each of "%DLLNAME.MyInterfaceName" . if that works, the object is a plugin. it works great. i can elaborate, if you'd like -c


        To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses.
           /. #3848917

        Fractals!

        L 1 Reply Last reply
        0
        • C Chris Losinger

          for the plugin system i use, i simply came up with a COM interface for the plugins and just told people that if they want to write a plugin for my apps they must: create an ATL object with this interface, name the object thusly, and place it in this folder. at runtime, my app scans that folder and finds all the DLLs there. then it does a CreateObject call on each of "%DLLNAME.MyInterfaceName" . if that works, the object is a plugin. it works great. i can elaborate, if you'd like -c


          To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses.
             /. #3848917

          Fractals!

          L Offline
          L Offline
          laphijia
          wrote on last edited by
          #4

          Chris Losinger wrote: for the plugin system i use, i simply came up with a COM interface for the plugins and just told people that if they want to write a plugin for my apps they must: create an ATL object with this interface, name the object thusly, and place it in this folder. Oh, this sounds very efficient. Can you indicate me to some documentation about COM interfaces, since I am profane? Thank You. "Nelle cose del mondo non e' il sapere ma il volere che puo'."

          C 1 Reply Last reply
          0
          • L laphijia

            Chris Losinger wrote: for the plugin system i use, i simply came up with a COM interface for the plugins and just told people that if they want to write a plugin for my apps they must: create an ATL object with this interface, name the object thusly, and place it in this folder. Oh, this sounds very efficient. Can you indicate me to some documentation about COM interfaces, since I am profane? Thank You. "Nelle cose del mondo non e' il sapere ma il volere che puo'."

            C Offline
            C Offline
            Chris Losinger
            wrote on last edited by
            #5

            COM is a huge subject. but, here is a link to a tutorial i wrote on how to create plugins for my apps. you can use VC's ATL wizard to do most of the work. to use these plugins, you need to create a COleDispatchDriver object and use it to create an instance of the plugin:

            // i chose to name my plugin interface "TNImgAutomation"
            cosnt char * pInterfaceName = "TNImgAutomation";

            // one of the plugin rules is that the plugin object's name must be the same as the DLLs name
            CString csPluginObjectName = csDLLName + pInterfaceName;

            COleDispatchDriver disp;
            BOOL ok = disp.CreateDispatch(csPluginObjectName);

            now we have a plugin object. the next part is to call methods of the plugin. this is where it gets tricky, in my system. because i create COleDispatchDriver objects directly, I am responsible for finding the methods and handling all of the method parameters myself. Here's how you get the DISPID of a method in an ActiveX object (DISPID is basically the enumerated ID of the method. each method will have a unique ID).

            HRESULT GetDispID(COleDispatchDriver &disp, const char *pName, DISPID &dispid)
            {
            USES_CONVERSION;
            LPOLESTR lpOleStr = T2OLE(pName);

            if (disp.m\_lpDispatch==NULL)
            {
            	ASSERT(0);
            	return E\_INVALIDARG;
            }
            
            return disp.m\_lpDispatch->GetIDsOfNames(IID\_NULL, &lpOleStr, 1, LOCALE\_SYSTEM\_DEFAULT, &dispid);
            

            }

            so you can do this:

            DISPID dispid;
            GetDispID(disp, "GetPluginName", dispid);

            now you know the ID of that method. now you can call it. here's how I call "GetPluginName" on a plugin:

            //////////////////////////////////////////////////////////////////////

            CString CTNPlugInBase::GetPluginName()
            {
            CString csOut;
            BSTR bsTemp;

            long result;
            static BYTE parms\[\] =
            	VTS\_PBSTR;
            disp.InvokeHelper(m\_GetPluginNamesDispID, DISPATCH\_METHOD, VT\_I4, (void\*)&result, parms, &bsTemp);
            
            csOut = bsTemp;
            SysFreeString(bsTemp);
            
            return csOut;
            

            }

            the tricky part here is that "parms" variable. that's where you list the parameters for the method. with one parameter (in this case a pointer to a BSTR: &bsTemp), it's pretty easy. but when you get more parameters, it looks like this:

            long result;
            static BYTE parms[] =
            VTS_PI4 VTS_PI4 VTS_PI4 VTS_I4 ;

            disp.InvokeHelper(dispId, DISPATCH_METHOD, VT_I4, (void*)&result, parms, MemoryHandle, Width, Height, Context);

            notice that there are no commas between those

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups