Plugin Extensions
-
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'."
-
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'."
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? -
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'."
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 -
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.
/. #3848917Chris 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'."
-
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'."
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