Re: How to program plugin DLL's
From: Jaime Stuardo (jstuardo_at_manquehue.net)
Date: 02/14/05
- Next message: Christopher Yeleighton: "Re: bug in CWinApp::ProcessShellCommand"
- Previous message: Jack Meijerink: "LoadBarState causing Assertion Failed when using two toolbars"
- In reply to: Joseph M. Newcomer: "Re: How to program plugin DLL's"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 07:55:46 -0300
Do you mean I have to call the corresponding GetProcAddress for all
functions when I first load the DLL's? That's the only way I can think I can
build the descriptor you mentioned.
I think in my case I cannot use the user-defined field for the menu since
that menu is subclassed in order to have a different look from the standard
one. That new menu class uses that data to accomplish it tasks.
But I think I can use the user-defined field of the items in the CTreeCtrl.
Each lParam member of the TVITEM struct may be filled with the pointer to a
class in the DLL.
That class is the "only" element to be exported from the DLL.
As you mentioned a super class, I have thought that I can have, in the main
application, a class that defines some virtual functions. One one them may
be "ExecuteCommand". All DLL's may derive and export a class from that
superclass.
When user clicks a menu item, by mean of its user-defined data I can get the
pointer to that class and then call something like this:
pointer->ExecuteCommand(nCmd);
In this case, pointer will be declared as the superclass, so I don't know if
I can call ExecuteCommand that is implemented in the derived class (so that
compiler doesn't send the error).
The disadvantage I see here is that I have the include the .H file, where
the superclass is defined, in all DLL's. That way, I make the DLL's source
code dependant on the H "distributed" with the main application.
Little by little I'm getting closer to the final solution I will implement,
I think :-)
Jaime
> ****
> Generally, you should do the GetProcAddress exactly once, when the DLL is
> loaded, because
> the lookup time is fairly high. Build a descriptor of the DLL; instead of
> a m_dwa array of
> what appears to be module handles, create an array of the descriptors
> which have the
> handle, and the various function pointers in it.
>
> What I might consider here is a method which fills in a popup menu. For
> example, reserve
> the menu item range 10000-11000 for popup menu items for your tree
> control. Then what you
> do is have an ON_COMMAND_RANGE handler that works in the
> MY_POPUP_RANGE_MIN (that's the
> 10000) to MY_POPUP_RANGE_MAX (that's the 110000) value, and simply
> dispatches to the DLL
> that is associated with the menu. Since each menu can have a user-defined
> field, this
> could be the pointer to the record in the table. So all you need is the
> popup menu handle,
> and knowing the index of the command, you retrieve the MENUINFO for the
> menu item, and use
> the dwMenuData field to retrieve the pointer to the DLL descriptor, or,
> alternatively, the
> pointer to the DLL method itself (this means all DLL menu methods need the
> same
> prototype). All DLLs would be derived from the same abstract superclass,
> so this should be
> fairly straightforward.
>
> Generally, you should keep pointers to objects instead of indices to
> arrays because array
> indices could change if a DLL were unloaded, or even if a new one is
> loaded.
>
> These are just some ideas; I used DLL descriptors with function pointers
> for the methods,
> because I had the same menu for all popups. So my handlers just called the
> method of the
> plugin. But it should generalize to supporting plugins with completely
> unrelated menus. No
> need to use the ID map if you have the direct pointers, and calling the
> DLL with an index
> to the menu item lets the DLL figure out what to do, and doesn't require
> knowing in
> advance how many items each DLL supports, or even what they mean, which is
> what it appears
> you are doing.
>>
>>Is this approach correct or is there a more elegant or easy way to
>>accomplish the same task?
>>
>>Thanks
>>Jaime
- Next message: Christopher Yeleighton: "Re: bug in CWinApp::ProcessShellCommand"
- Previous message: Jack Meijerink: "LoadBarState causing Assertion Failed when using two toolbars"
- In reply to: Joseph M. Newcomer: "Re: How to program plugin DLL's"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|