How to provide plugin interface (command design pattern) in VC++ 6

I need to provide a plugin interface in my application. On the basis of 
selected plugin, the excution is transferred to the plugged in code. I see 
it very easy in .net by using reflection. Even in c++ i can use COM and 
IDispatch for this .... but the problem is ... the plugin could call various 
methods of the exe as well to get the state and other operations ... how can 
i let COM call my exe methods .... should i pass some sort of interface to 
COM. REMEMBER: I donot want my exe be compilied again and again with the new 
plugins been added ....

Now let me explain what my exe does ........

It has a functionality to add cryptography that can be provided by the 
client ..... my exe would call Encrypt() , Decrypt() from COM. This i can 
call by using IDispatch and providing ProgId as parameter like "RSA.RSA256" 
or "SHA.SHA1.1". All these would implement an interface that would provide 
declration for Encrypt() and Decrypt() ..... But COM could also call some 
functions from my exe like IsAppAlive() etc. How can i let com call my 
interface ...plz help .... I know this has been done before in c++ ....... 


0
Mubashir
11/20/2006 4:40:13 PM
vc.mfc 33608 articles. 0 followers. Follow

10 Replies
568 Views

Similar Articles

[PageSpeed] 39

Theres no perfect answer for this. It all depends upon how you expose
the functionality to plugins.

- Are your plugins going to be written in C++ only? If yes, why are you
using COM to communicate with plugins? Simply expose the functionality
thru a c++ class and provide the relevant header. There is nothing
wrong in using COM here but its an overkill.

If plugins are developed using any IDispatch supported language (VB,
..Net etc), you will need to expose all the functionality thru a COM
object(s). What you have in your code has no meaning unless you expose
it.

---
Ajay



Mubashir Khan wrote:
> I need to provide a plugin interface in my application. On the basis of
> selected plugin, the excution is transferred to the plugged in code. I see
> it very easy in .net by using reflection. Even in c++ i can use COM and
> IDispatch for this .... but the problem is ... the plugin could call various
> methods of the exe as well to get the state and other operations ... how can
> i let COM call my exe methods .... should i pass some sort of interface to
> COM. REMEMBER: I donot want my exe be compilied again and again with the new
> plugins been added ....
>
> Now let me explain what my exe does ........
>
> It has a functionality to add cryptography that can be provided by the
> client ..... my exe would call Encrypt() , Decrypt() from COM. This i can
> call by using IDispatch and providing ProgId as parameter like "RSA.RSA256"
> or "SHA.SHA1.1". All these would implement an interface that would provide
> declration for Encrypt() and Decrypt() ..... But COM could also call some
> functions from my exe like IsAppAlive() etc. How can i let com call my
> interface ...plz help .... I know this has been done before in c++ .......

0
ajaykalra (6842)
11/20/2006 7:10:31 PM
No,  a plug-in would NEVER call a method of the executable.  That defeats much of the
value of a plugin.  Instead, pass in a CWnd* or an HWND, and send messages to it as
required.  That's your callback to the app.
					joe


On Mon, 20 Nov 2006 10:40:13 -0600, "Mubashir Khan" <m@n.com> wrote:

>I need to provide a plugin interface in my application. On the basis of 
>selected plugin, the excution is transferred to the plugged in code. I see 
>it very easy in .net by using reflection. Even in c++ i can use COM and 
>IDispatch for this .... but the problem is ... the plugin could call various 
>methods of the exe as well to get the state and other operations ... how can 
>i let COM call my exe methods .... should i pass some sort of interface to 
>COM. REMEMBER: I donot want my exe be compilied again and again with the new 
>plugins been added ....
>
>Now let me explain what my exe does ........
>
>It has a functionality to add cryptography that can be provided by the 
>client ..... my exe would call Encrypt() , Decrypt() from COM. This i can 
>call by using IDispatch and providing ProgId as parameter like "RSA.RSA256" 
>or "SHA.SHA1.1". All these would implement an interface that would provide 
>declration for Encrypt() and Decrypt() ..... But COM could also call some 
>functions from my exe like IsAppAlive() etc. How can i let com call my 
>interface ...plz help .... I know this has been done before in c++ ....... 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
11/20/2006 7:39:07 PM
"Mubashir Khan" <m@n.com> wrote in message
news:uMWGjKMDHHA.4024@TK2MSFTNGP04.phx.gbl...
> I need to provide a plugin interface in my application. On the basis of
> selected plugin, the excution is transferred to the plugged in code. I see
> it very easy in .net by using reflection. Even in c++ i can use COM and
> IDispatch for this .... but the problem is ... the plugin could call
various
> methods of the exe as well to get the state and other operations ... how
can
> i let COM call my exe methods .... should i pass some sort of interface to
> COM. REMEMBER: I donot want my exe be compilied again and again with the
new
> plugins been added ....
>

This can be done using Lua scripts.  With Lua, your program can call
functions in a Lua script.  In addition, your program can expose functions
that can be called from the Lua script.

Basic Lua is described at www.lua.org .  It does not tell you how to get the
two-way interaction described above.

For one example that helps to achieve the two-way interaction, see
www.lua-plus.org

Mike


0
11/20/2006 8:15:26 PM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:a014m215453hngjp1dbpr2o93mm9nhc0ld@4ax.com...
> No,  a plug-in would NEVER call a method of the executable.  That defeats
much of the
> value of a plugin.  Instead, pass in a CWnd* or an HWND, and send messages
to it as
> required.  That's your callback to the app.
> joe
>
>

I would tend to disagree with this.  To me, the design of a tight API into
your application, which would allow a plug-in to call methods in the app, is
one of the great benefits of a plug-in architecture.

Of course it's possible for a plug-in to send messages to HWND's etc, but
that should not be the only avenue for interaction with the app.

Mike


0
11/20/2006 8:19:43 PM
> This can be done using Lua scripts.  With Lua, your program can call
> functions in a Lua script.  In addition, your program can expose functions
> that can be called from the Lua script.

If the functionality is exposed to be used by Lua, why cant it be
called directly by the plugin? Why bring-in Lua at all into picture?

---
Ajay

0
ajaykalra (6842)
11/20/2006 8:45:41 PM
and how does it name them?  It might take a set of pointers to static methods, but that is
rather tedious; there's no other way to get function pointers available.  If you use
function pointer interfaces, you're usually better off going to ActiveX and taking
advantage of the various event notification mechanisms, which regularizes the interface.

For most plugins, the solution is to use messages.  

Another solution is to break out the useful functions from the .exe and create a separate
DLL.  Then the plugin can at least us GetProcAddress to resolve the function names in the
various DLLs you create, although this is almost as bad as the struct-of-function-pointers
approach.

I've done a lot of plugins using messages, and they work exceedingly well.  The behavior
is nicely decoupled.  
					joe

On Mon, 20 Nov 2006 12:19:43 -0800, "Michael K. O'Neill"
<MikeAThon2000@nospam.hotmail.com> wrote:

>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>news:a014m215453hngjp1dbpr2o93mm9nhc0ld@4ax.com...
>> No,  a plug-in would NEVER call a method of the executable.  That defeats
>much of the
>> value of a plugin.  Instead, pass in a CWnd* or an HWND, and send messages
>to it as
>> required.  That's your callback to the app.
>> joe
>>
>>
>
>I would tend to disagree with this.  To me, the design of a tight API into
>your application, which would allow a plug-in to call methods in the app, is
>one of the great benefits of a plug-in architecture.
>
>Of course it's possible for a plug-in to send messages to HWND's etc, but
>that should not be the only avenue for interaction with the app.
>
>Mike
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
11/20/2006 9:41:52 PM
"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:1164055541.383783.235000@f16g2000cwb.googlegroups.com...
> > This can be done using Lua scripts.  With Lua, your program can call
> > functions in a Lua script.  In addition, your program can expose
functions
> > that can be called from the Lua script.
>
> If the functionality is exposed to be used by Lua, why cant it be
> called directly by the plugin? Why bring-in Lua at all into picture?
>
> ---
> Ajay
>

Because Lua is a text-based scripting language that does not require
compilation by the end-user, or anything more complicated than an ordinary
text editor.

Mike


0
11/20/2006 10:16:30 PM
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
news:a184m2tpq7mld2abaq6da47e9if8nja305@4ax.com...
> and how does it name them?  It might take a set of pointers to static
methods, but that is
> rather tedious; there's no other way to get function pointers available.
If you use
> function pointer interfaces, you're usually better off going to ActiveX
and taking
> advantage of the various event notification mechanisms, which regularizes
the interface.
>
> For most plugins, the solution is to use messages.
>
> Another solution is to break out the useful functions from the .exe and
create a separate
> DLL.  Then the plugin can at least us GetProcAddress to resolve the
function names in the
> various DLLs you create, although this is almost as bad as the
struct-of-function-pointers
> approach.
>
> I've done a lot of plugins using messages, and they work exceedingly well.
The behavior
> is nicely decoupled.
> joe
>

You're thinking about interfaces that are too complicated for an ordinary
end-user.  There are very few end users who have the skills and inclination
to understand how to use and build ActiveX plug-ins, or to understand how to
use GetProcessAddress to write and compile a program that accesses DLLs.

The nice part of Lua is that the end user can write text-based scripts with
an ordinary text editor that do not need compilation.  The scripts are
called by your (say) C++ program, and your C++ program can expose functions
that the text-based scripts can call.  Yes, they call the functions by
"name".

Mike


0
11/20/2006 10:22:47 PM
my plugins would be written in C++ .... thus i can make use of the dll (not 
COM) ..... now i understand loadlibrary and getprocaddress etc .... but how 
can i expose interface of my exe ..... the interface would be a class not 
global function ..... and even if i pass a class pointer and provide header 
file .... would not there be linker error .... unresolved external symbol 
......??????

"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message 
news:1164049831.452191.167000@j44g2000cwa.googlegroups.com...
> Theres no perfect answer for this. It all depends upon how you expose
> the functionality to plugins.
>
> - Are your plugins going to be written in C++ only? If yes, why are you
> using COM to communicate with plugins? Simply expose the functionality
> thru a c++ class and provide the relevant header. There is nothing
> wrong in using COM here but its an overkill.
>
> If plugins are developed using any IDispatch supported language (VB,
> .Net etc), you will need to expose all the functionality thru a COM
> object(s). What you have in your code has no meaning unless you expose
> it.
>
> ---
> Ajay
>
>
>
> Mubashir Khan wrote:
>> I need to provide a plugin interface in my application. On the basis of
>> selected plugin, the excution is transferred to the plugged in code. I 
>> see
>> it very easy in .net by using reflection. Even in c++ i can use COM and
>> IDispatch for this .... but the problem is ... the plugin could call 
>> various
>> methods of the exe as well to get the state and other operations ... how 
>> can
>> i let COM call my exe methods .... should i pass some sort of interface 
>> to
>> COM. REMEMBER: I donot want my exe be compilied again and again with the 
>> new
>> plugins been added ....
>>
>> Now let me explain what my exe does ........
>>
>> It has a functionality to add cryptography that can be provided by the
>> client ..... my exe would call Encrypt() , Decrypt() from COM. This i can
>> call by using IDispatch and providing ProgId as parameter like 
>> "RSA.RSA256"
>> or "SHA.SHA1.1". All these would implement an interface that would 
>> provide
>> declration for Encrypt() and Decrypt() ..... But COM could also call some
>> functions from my exe like IsAppAlive() etc. How can i let com call my
>> interface ...plz help .... I know this has been done before in c++ 
>> .......
> 


0
mubi (159)
11/21/2006 1:41:13 PM
Mubashir Khan wrote:
> my plugins would be written in C++ .... thus i can make use of the dll (not
> COM) ..... now i understand loadlibrary and getprocaddress etc .... but how
> can i expose interface of my exe ..... the interface would be a class not
> global function ..... and even if i pass a class pointer and provide header
> file .... would not there be linker error .... unresolved external symbol
> .....??????

If your plugins are all C++ modules, you can expose your app's
functionality thru a class and provide header files. You will need to
provide appropriate .lib files that your functionality depends upon.
This requires proper designing of functionality so that only necessary
modules needs to be shipped for building plugins. You are essentially
writing an object model for you  app. Once clients have developed
plugins(DLLs), you will need a way to load these at run time. You will
need to provide some mechanism (location) using which these DLLs can be
loaded (LoadLibrary).

---
Ajay

0
ajaykalra (6842)
11/21/2006 2:20:09 PM
Reply:

Similar Artilces:

Conditional commands on filtered lists
-I'm a spreadsheet neat freak, so I like to keep my data in as few cell as possible. Just a warning that I don't want to generate columns o rows that won't have useful end-product info in them.- I have a sheet of business transactions, and I'm really only concerne with From, To, Type, and Cost. Only transactions of the "service" typ matter to me, and I'm supposed to make a summary of each division' transactions to itself. I also don't like messing up the original formatting I was given--I wa given the chart with autofilters on the top line. For any ot...

Exchange 2003 / Groupshield 6 problems
Hi all Sitting here at 1pm on Sunday - NT4/exchange 5.5-->2003/2003 migration has gone reasoably well and is now "live". Thank god for a test lab! Only problems we can now find are that some messages when read "hang" RPCServ.exe on the server which is a Groupshield 6 module. When this hangs, a client mailbox will also freeze. Killing the process releases the client, but then the message body doesn't show.... Can't find anything on this anywhere apart from some references to a Beta version of GSE - but no solution. One message that kicks this problem off re...

Service provider
Is anyone out there a Publisher service provider? I heard somewhere tha Microsoft has a program where the list you as a provider on a web site. How does one get into this program? Rich While in a state of withdrawal waiting for components to arrive to repair his dead laptop, Ed notices a message from "Rich Sommer" <rpsommer@itsalldigital.com>. > Is anyone out there a Publisher service provider? I heard somewhere tha > Microsoft has a program where the list you as a provider on a web site. > How > does one get into this program? http://mspublisher.saltmine.com/...

taking the techchek test for visual C++ 6
Hi all- a prospective employer wants me to take an on-line test on ikmnet.com on visual C++ 6. it has been about a year since i have done anything with VC++ 6, and then it was a rather small document/view application and help files to go along with it. i have until 8/16 to take it. any ideas. thanx. > a prospective employer wants me to take an on-line test on ikmnet.com > on visual C++ 6. it has been about a year since i have done anything > with VC++ 6, and then it was a rather small document/view application > and help files to go along with it. i have until 8/16 to take it. ...

Import/Export command missing
I am running Outlook 2002 on XP Pro. I can't find the import/export command under the File tab!!! How can I restore it? Thank you. Cyril ...

Provider: Named Pipes Provider, error: 40 & error 53?????????????
Problem: How can I access SQL server on WAN???????????????????????????????? ----------------------------------------------------------- Error: (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53) ------------------------------------------------------------------------ Information: Windows Sever 2008 (64bit OS) Service Pack 2 Microsoft SQL 2008 Server Management Studio (10.0)(64bit) Microsoft .Net Frame work 3.5 SP1 ------------------------------------------------------------------------------ Additional Inform...

Interface into GP 8.0
I'm running GP 8.0 and SQL 2000. Does anyone know of any interface for order release plus sending orders information extraction by FTP? What I’m trying to do is when the line items become allocated / fulfilled to automatically extract the information and send it via FTP or any other none source. For billing purpose once the orders have been shipped I want to find a way of creating a batch from the shipping report, possibly automate the transfer from Sales Order to Invoice. What is the easiest way to accomplish these interfaces? Thank you, Do you have a Warehouse Management Syst...

Internet Explorer. 6.0
I have purchased the 2003 Basic version of Quickbooks. One of the requirements is that my system upgrade Internet Explorer to 6.0. This update is included on the disc purchased. However every time I try to install it it freezes at 87% of the download. I have had competer technitions here to assist and even they cannot figure it out. I am getting desperate. anyone with ideas or solutions, I am willing to listen. Please advise. Thank you. ...

Commands will not run
I converted from Access 2003 to Access 2007 my previous commands and queries will not run. On Oct 13, 1:10 pm, guycpsi <guyc...@discussions.microsoft.com> wrote: > I converted from Access 2003 to Access 2007 my previous commands and queries > will not run. Access 2007 will disable your code if the source file of your DB is not in a "Trusted" location. If you click the Office button in the upper left corner, then go to Access Options, you should be able to add your source file to the trusted locations list. HTH ...

Future for VC++ Programmers
Being a VC++ Programmer what are your future plans? are you changing from VC++ to anything else? what new technology are you learning? what kind of projects you are concentrating on?? > Being a VC++ Programmer what are your future plans? Stay employed. > are you changing from VC++ to anything else? what new technology are you learning? Moving on to C#, mostly by need rather than choice. I personally dont see any major threat to C++ programmer for years to come. --- Ajay I would consider managed VC++ as something I should be looking at; and I know enough C# to be dangerous, altho...

GP Support Providers
Anyone know of a good list or website to find companies that provide service and sales of GP products in U.S.? The distributor for our area provided less than ideal initial startup support and we are looking for an alternative. We possibly need new modules and support for existing modules. Brad Email me at haribhagat@hotmail.com and I can help you locate one. "Brad" wrote: > Anyone know of a good list or website to find companies that provide service > and sales of GP products in U.S.? The distributor for our area provided less > than ideal initial startup suppor...

Design puzzle
I have a form with several combo boxes on it, the last of which allows the user to type in new data. Depending on the contents of all of the combo boxes, a routine executed in the before_update event enables or disables a command button. The users don't learn to tab off of the combo box after typing new data into it because when they choose from the list, the command button gets enabled or disabled immediately. I can't find any way to ascertain the contents of that last combobox until the user tabs off of it. Key_up and similar events only know about the previous contents. ...

CRM Provider for Service provider
does microsoft provide a trial version or where i can download the CRM 3.0 Professional for Service Provider Edition? A very good and easy-to-remember link is www.microsoft.com/dynamics/crm. In includes a download link (http://www.microsoft.com/dynamics/crm/using/downloads/default.mspx) and on this page you find trial versions and a lot of related documentation. -- Michael H�hne, Microsoft Dynamics CRM MVP Web: http://www.stunnware.com/crm2 Feed: http://www.stunnware.com/crm2/atom.aspx Custom Lookup Dialog: http://www.stunnware.com/crm2/?area=customLookup --------------------------...

Command Button #5
I have a command button on Sheet 1. I want a user to go to Sheet 2 if value in L4 = 0, Sheet 3 if value in L4 = 2, Sheet 4 if value in L4 = 4. How do I do this? THK in Advance try to introduce this code under command button code If Sheet1.Range("L4") = 0 Then Sheet2.Activate If Sheet1.Range("L4") = 2 Then Sheet3.Activate If Sheet1.Range("L4") = 4 Then Sheet4.Activate see whether you get what you want ==================== Chris Hale <ChrisHale@discussions.microsoft.com> wrote in message news:792D6754-223E-4DE0-AA69-DE63BA91CCE7@microsoft.com... > I...

External mail from the command line
HI all, I hope someone can help with my exchange 5.5 problem. In the environment we have 2 IMC servers which are both giving different results when sending mail via a command line to external recipients only, internal is fine. Both machines are windows 2000 with exchange 5.5ent both at the same patch and SP level (4) and have been configured the same and to forward mail to a host (our mail appliance). The one that is concerning me is the one that just returns the mail back to the sender stating that it cant find the recipient (external recipient). Now surely it should just be forwarding...

ESS unable to load consumer provider NTEventLogEventConsumer from provider subsystem: 0x80041013
Any one Please tell me root cause of this Error and Resolution This error occured in C:\WINDOWS\SYSTEM32\WBEM\LOGS\wbemess.log file, the error is the following ESS unable to load consumer provider NTEventLogEventConsumer from provider subsystem: 0x80041013 Failed the first attempt to retrieve the sink to deliver an event to event consumer NTEventLogEventConsumer="SCM Event Log Consumer" with error code 80041013. Please answer the following 1. Which component is causing the issue 2. Why is it happening? 3. Fix for this issue. ...

Search providers
When trying to ad Google or any other search engine as new search provider, I got an error page. Of course, we all know what the error message said. And no need to tell us what version of Internet Explorer you're using or what version of Windows you have. We'll just consult the spirit world. --- Leonard Grey Errare humanum est pallarfa wrote: > When trying to ad Google or any other search engine as new search provider, I > got an error page. If you type 'http://www.google.co.uk' you will see the Google home page. If you type 'http://www.google.c...

Messaging Interface Problem in Outlook 2003
The messaging interface has returned an unknown error. If the problem persists, restart Outlook. Was doing normal work online and to my knowledge, nothing happened across the board. Now, I cannot open a new eMail form or forward an existing eMail...also, I can "see" what's on the HOTMAIL server, but cannot send/receive (does nothing). I looked at the above problem and found a MS KB issue for this in Outlook 2002, but not 2003. Restarting OL or the CPU does nothing. Thoughts? Casey Hi Casey, Please try to start Outlook in Safe Mode. Safe Mode will disable all add...

How can I get all commands to show on the menu
Other than selecting "show full menu", how do I get all commands to show on the menu? For example, the file menu does not display "save as", the tool menu does note display "options" It would help if you would tell us which version of Word you're using, as the settings vary slightly among versions. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Pam D" <Pam D@discussions.microsoft.com> wrote in message news:14C3526C-6635-4667-A40C-C140892B8621@microsoft.com... >...

Need Keystroke Commands to Recover a Deleted Item
Does anyone know if keystroke commands exist for Recovering Deleted Items? I have a blind user who uses JAWS. She does not use a mouse, but rather a JAWS cursor. The JAWS cursor does not access the necessary button to recover a deleted item. Do keystroke commands exists for this function? And if so, can someone please post them here? Thanks so much!! esrichie ...

Lost my menu bar commands
I don't know what I did, but somehow my menus have been corrupted in Excel. The Insert menu contains only the Format command, and the Tools menu contains only the Spelling, Autocorrect and Goal Seek commands. How do I get the normal menus back? Go to Tools>Customize>Toolbars Select Worksheet Menu Bar from the list, and hit Reset -- HTH RP (remove nothere from the email address if mailing direct) "pod" <pod@discussions.microsoft.com> wrote in message news:2A18E951-FE93-4F72-9643-46A94904D6CC@microsoft.com... > I don't know what I did, but somehow my...

Linkmasterfields property setting has provided this error: 'Return
Hi I'm currently getting this error message when I open my database: Linkmasterfields property setting has provided this error: 'Return without GoSub' How do I resolve this issue? This message started after I created a text box which I use to calculate the age of a student. Thank you for your help in advance. When you get the error message, click the button on the error dialog. It will take you back to the procedure where the eror is occuring. You have a Return statement that does not belong on the routine. Probably you once had GoSub code to branch...

Logon Credential Prompts When Using Third Party Exchange Providers
After migrating to a third party Exchange provider (i.e. with an external domain) the MS Outlook clients with Full Exchange prompt for authentication credentials to sign-in with their password every time they open Outlook. Is there a setting or a script (or anything at all) that could be run or implemented in order to disable the constant and frequent prompting for a password every time they open Outlook. TIA, e. E-Double wrote: > After migrating to a third party Exchange provider (i.e. with an external > domain) the MS Outlook clients with Full Exchange prompt fo...

Ole Db Provider
I want to use my custom Ole Db Provider that I wrote, to get some data into excel. I have tried the "Get External Data" feature, but my Ole Db provider does not appear in any of the lists. (However it is registered, as Borland Builder included it in it's list of providers it can access)??? Any suggestions??? ...

MDI design question (kind of long)
Hello, I have some legacy code that needs a slight tweek and I'm having trouble figuring out how Visual C++ is supposed to help me accomplish the task. I didn't write the original code and it seems to do things a bit different than what the documentation states things should be used for. After a couple days reading documentation and notes on the MDI Template Documents I've decided a little help is needed. Okay, my application is based on the MDI Templates. Each of these documents is roughly a view into a database. One of these views, I'll call it "UserView"...