Solved

Using COM (or DLLs) to make data-access routines customizable by (smart) end-users.

Posted on 2000-03-25
12
233 Views
Last Modified: 2013-11-20
Overview:
I have built an inventory analysis algortihm that must be customized by the end user to integrate with legacy data systems. I want to architect the application in a way that simplifies the integration.

Details:
The demo version of my application uses global functions like this one:

int GetInventory(COleDateTime sampleTime, int resourceID)
{
      // Use input data to seed random number generator.
      srand(resourceId + sampleTime.GetDay());
      // Generate random data for demo implementation.
      return (rand()%20);
}

Instead of retrieving data from a database or other source the demo version just makes the data using a random-number generator. When integrated in a real business environment, the logic should be changed to retrieve the data from a real database. Therefore, any end-user my application would want to customize the definition of this function to pull data out of their own database and possibly do related computations.

To facilitate the customization, I might give the end-user the entire source code for my application and let them alter the implementation of GetInventory() and recompile.

That's a bit sloppy, however, and I would like to know a more professional approach to acheiving the same purpose. I think COM can help, but I need guidance.

Work In Progress:

I guess I could define a simple COM object "IMyDataAccessRoutines" that my application uses and change the implementation of GetInventory to:

int GetInventory(COleDateTime sampleTime, int resourceID)
{
      int response(0);
      IMyDataAccessRoutines* pMyDataAccessRoutines;
      HRESULT hr = CoCreateInstance(???,???,(void**)pMyDataAccessRoutines);
      if(SUCCEEDED(hr)) {
            pMyDataAccessRoutines->GetInventory(sampleTime, resourceId, response);
            pMyDataAccessRoutines->Release();
      }
      return response;
}

If I put the rand calls in the COM object implementation and deliver the COM object as a DLL, then the end-user could customize the application by building his own version of this COM object and replacing the DLL on his system.

Question:
How do I make this work correctly?
COM is so confusing that I am sure I will make some mistakes if I don't get a little help.

What I would ideally like to see is complete instructions for dealing with this simple example.
The solution should say how to:
1) Implement the global function GetInventory()
2) Build the default COM object or other DLL.
3) Build the end-user COM object or other DLL.
4) Switch the application at run-time back and forth between using the orignal or end-user version of the DLL.

The example is simple and clear, so I am really hoping for a clear explanation for this particular case.

Cheers,
Diana
0
Comment
Question by:djelescu
  • 7
  • 2
  • 2
  • +1
12 Comments
 
LVL 1

Author Comment

by:djelescu
Comment Utility
Adjusted points from 200 to 250
0
 

Expert Comment

by:sisimon
Comment Utility
   From y u explenation I know this things.  U have a logic(like a random number generator).U also allow changes in u r fun:(Not the source code of random number generator).So u can use com here(If u r COM object contain only random number generator(only srand function why u change it as a com,only one advantage is u can reduce the  recompilation time).

  sisimon@usa.net
0
 
LVL 2

Expert Comment

by:tdubroff
Comment Utility
...um what?
0
 
LVL 1

Author Comment

by:djelescu
Comment Utility
Adjusted points from 250 to 270
0
 
LVL 1

Author Comment

by:djelescu
Comment Utility
sisimon- It seems like your answer was actually a question. Here is my response:

I want to make it easy for end-users of my product to replace routines like GetInventory(), which presently mimics data-access behavior using rand, with real data access routines that connect to proprietary databases etc.

However, I don't want to alter my source code for each customization because my source code is proprietary and they are the ones doing the customization.

And I don't want them to recompile the application using object files because that also is unprofessional. My application should be compiled by me.

If the end-user can implement the data-access routines in a DLL and direct my program to use that DLL, then the problem is solved. I just need to give specifications for them to use in building their DLL. (And support run-time switching between the original and new DLL).

This is why I am interested in the COM/DLL approach.
0
 
LVL 2

Expert Comment

by:tdubroff
Comment Utility
I too am starting to look into COM do something very similar.  I've been reading Inside COM which is pretty good, but I haven't tried any applications yet.  You may want to email dbox@develop.com.  I think he is an industry-recognized expert on COM.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:djelescu
Comment Utility
Adjusted points from 270 to 280
0
 
LVL 1

Author Comment

by:djelescu
Comment Utility
tdubroff-
Thanks for the tip!
I wil post anything I learn from dbox.
Regards,
-Diana
0
 
LVL 1

Author Comment

by:djelescu
Comment Utility
Adjusted points from 280 to 350
0
 
LVL 2

Accepted Solution

by:
christophm earned 350 total points
Comment Utility
Hi djelescu.

I believe you will find a concise and easy to find example of how to write automation and ActiveX in Kruglinski, "Inside Visual C++".  I believe the book is in the fifth edition, in the fourth edition that i have you should follow through the first two examples in chapter 24.  Using just those two examples you will know how to write a self-registering automation component.

The simple bank deposit example in Kruglinski's book will have to be modified to support the generality and user customization you want.

In brief : Your program utilizes an/the automation component to do the data base access (functions) and you specify in your program the 'data characteristics' that are important to your main program code; for example,
  char     szOrderNumber[26];
  char     szCustomerName[51];
  int      fOrderValue;

in the automation component you will have to build 'methods' (functions) that return values that you use in your main program to 'fill' the 'OrderNumber', 'CustomerNumber', etc. fields.  this is all explained in the book.

All the DB access will be in your component and can be modified 'site to site' to fit each customer's particular DB server software.  BTW - this is pretty close to the kind of archicture that microsoft's three tier (DNA) concept describes.

You SHOULD give each customer example  source code for say... SQL Server.

You MUST (MUST!) tell each customer what methods they MUST include in their component (because your program depends upon finding those methods!) and you must tell each customer what the data items ('CustomerNumber', 'OrderValue', etc.) look like; i.e., char[26], float, etc.

One last thing - if you wish to avoid modifying your main program you must have the different users use the same 'name' for the component - then your main program will know what string to look for in the registry and your main program will not have to be modifed - or the source code delivered - site to site.

Another last thing.  I believe you will be very satisfied with this solution - the fifty bucks for the Kruglinski book is a bargain for just this one technique and the book is loaded with lots of other good stuff.  You are doing something a little strange in that Customer #1 will have a component named perhaps "djelescus_component" and Customer #2 will have a component named the same ("djelescus_component").  The two components are different and you will have to mind your p's and q's to keep straight which customer is using which actual component since you have them named the same!

I am not including any sample code or detail explanation of how to do this - it is explained PERFECTLY in the Kruglinski book and i would just be copying from the book.
0
 
LVL 1

Author Comment

by:djelescu
Comment Utility
Thank you for your response.
I think your reference is a good one.

I leave the topic ungraded for now so that my colleagues can consider the issues here as well.
I will close the topic on Monday, awarding your answer with a B grade.

Feel free to add more comments to raise your grade from a B to an A.

Especially I am interested in an organized, safe way for someone to create a DLL from scratch that will work with my program even though my program was made first, which is what makes this unusual.

Regards,
-Diana
0
 
LVL 2

Expert Comment

by:christophm
Comment Utility
Hi djelescu,

If you are still pursuing COM you should check out: "Active Template Library, A Developer's Guide", by Tom Armstrong, ISBN: 1-55851-580-1  This is an excellent book.  thanks - christophm
0

Featured Post

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.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
if loop in java 3 114
viewing source code from eclipse 13 74
VBA "SendKeys" Syntax for Multiple Keystrokes 7 97
withoutTen challenge 14 87
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

13 Experts available now in Live!

Get 1:1 Help Now