Solved

ActiveX or Vanilla DLL - Can multiple objects dynamically support the same Interface and be swapped out at run-time?

Posted on 2003-11-13
12
310 Views
Last Modified: 2013-11-20
I am working on an MFC app.

I have created several classes with the same name and public methods, though each implement those methods quite differently.  For example, lets say that they all have the same method that takes a string input, though each class searches for a different regular expression on that string and returns true or false based on its findings.

I want to be able to load a single instance of one of these objects into my MFC app during run-time, to which the user can pass strings to.

 I also want to be able to unload the current instance of this object and reload an instance of one of the other class objects at run-time to allow for the user to search using another regular expression.  This way, the application only has to know about the single interface that each class supports and the existence of the dll's or controls from which it can select to load.

I am not sure if I am barking up the wrong tree, or if the simplified example above can be implemented using ActiveX controls or just plain dll's or not.

I want to be able to easily give the user a new Control or dll in the future that will add further functionality.

Will the AtiveX or COM techology work for me in this regard?
0
Comment
Question by:Skytzo
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9738086
From a plain dll you can't export a class.  You can export functions but with different names.  Different dll's can export functions with the same name.

So you could have one dll and export Fn1, Fn2, Fn3... to manipulate the string differently.
Or you could have multiple dlls and LoadLibrary(Dll1, Dll2, Dll3...) followed by calling the function of the same name in each.

An alternative you haven't specified is one dll, one function BUT passing multiple arguments.
bool Fn1(LPSTR pszText, int iUseThisFunctionality) where this function in the dll has a switch to passs it onto the desired class for further processing.  [Future version just need more case statements in the switch]
0
 
LVL 9

Assisted Solution

by:_ys_
_ys_ earned 450 total points
ID: 9738556
>You can export functions but with different names.
I have to disagree.

This is true when you circumvent name mangling using extern "C" or a .def file.
However, using plain vanilla __declspec(dllexport) allows you to export multiple functions with the same name - so long as they are true overloads of each other (different parameters etc.). That's why C++ mangles its function names.
Granted, it does make GetProcAddress calls messy, as the mangled names have to be known. But it is possible.

>Will the AtiveX or COM techology work for me in this regard?
Yes, but be careful, because ...

>each implement those methods quite differently
Within COM, the function (and interface) semantics have to be exact and immutable.
It is suited - I not saying it isn't - just word your semantics properly.


Final note. This really sounds like a textbook case for COM monikers.
0
 
LVL 4

Expert Comment

by:inox
ID: 9738739

as far as I understood your question, this is exactly one of the targets of COM.
Both things are possible, two or more classes can implement the same interface, or two or more classes can implement different interfaces with equal names.
The first case is not so obvious because the VC Wizard does not provide that (at least upto VC6.0 doesn't) but COM is not limited to that what wizards can do.

Imagine e.g. the Value property of an Office application this applies to more than a dozen of components
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9738822
Hi _YS_
>You can export functions but with different names.
I have to disagree.

Yes, you are correct re differing parameters.  However the question was about having the same input parameters (string, or so it seemed to say).  Hence the export would not work as I understand it as the function name, return and calling parameters would be the same.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9739026
AndyAinscow,

I realise your point was made within the context of the question.

My intentions were to make Skytzo aware that it is possible, as he does not sound as experienced as some, and may take your comment out of the context of the question.

>I have to disagree.
This could have been worded better, so as not to 'critisise'. Apologies.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9739270
_ys_
no offence taken, it was a valid criticism.  You were correct in that I made a sweeping statement rather than qualifying to the questioners point specifically.

Thanks for the apologies.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Author Comment

by:Skytzo
ID: 9740773
I have upped the points for more help.

Thanks for the comments so far.   I will look skip a few chapters ahead and read about Monikers.

To clarify some misunderstanding, here is better explanation of what my application will do.

In short, My application will read a stream of data coming in from an outside source though through a single interface, for example, through a single tcp connection.  There can be multiple sources on the outside that the user can select from which then allows the user to have the ability to change which source he is receiving from dynamically while the app is running.  Based on the source of the stream, the data needs to be passed to an ActiveX control or somethng similair that can interpret the data correctly.  I also want to easily be able to support the adaption of future streams or different comibinations of streams.  

I am wondering now if I need to have the interpretation of all of the streams inside a single COM object, or if I can still split the interpretation of each kind of stream to a different Object and allow the application to support streams that it has never seen before or that were not shipped with it when released?

Does that make more sense?  I have coded a fair amount in MFC prior to this, though never with COM.
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9741610
>I also want to easily be able to support the adaption of future streams or different comibinations of streams.

As I said, textbook example for COM monikers.

>I will look skip a few chapters ahead and read about Monikers.
Happy reading.
I must point out, though not to deter you, monikers are the least used, and least understood of all the COM mechanisms out there. Take is slow. Skipping a few chapters will confuse you, no doubt about it. Better to read the background as well.

Any questions just ask.
0
 
LVL 9

Accepted Solution

by:
_ys_ earned 450 total points
ID: 9741660
If you're hungry for source code to see how monikers really work [or a glutton for punishment], take a look at this:

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20775283.html

It does required a basic grounding in COM before reading.
0
 
LVL 1

Author Comment

by:Skytzo
ID: 9741746
Here is another question.  Are Monikers supported from Win95.x through XP ?  Or only from NT onwards?
0
 
LVL 9

Expert Comment

by:_ys_
ID: 9746492
Moniker support has been there since the incarnation of OLE1 itself. Back in the days of NT 3.1.

Win 9x supports it as well - going back to Win95 of course (verisons a & b).
0
 
LVL 1

Author Comment

by:Skytzo
ID: 9795036
Thanks for the comments.

I have found a simpler solution to my problem that avoids having to touch the registry.  I will use Comm in future products though.

See
http://www.codeproject.com/dll/plug-in.asp?target=dll%7Cloader
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now