Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2000-03-25
12
Medium Priority
?
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 2
  • 2
  • +1
12 Comments
 
LVL 1

Author Comment

by:djelescu
ID: 2659391
Adjusted points from 200 to 250
0
 

Expert Comment

by:sisimon
ID: 2659873
   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
ID: 2660660
...um what?
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 1

Author Comment

by:djelescu
ID: 2661031
Adjusted points from 250 to 270
0
 
LVL 1

Author Comment

by:djelescu
ID: 2661032
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
ID: 2661369
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
 
LVL 1

Author Comment

by:djelescu
ID: 2662082
Adjusted points from 270 to 280
0
 
LVL 1

Author Comment

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

Author Comment

by:djelescu
ID: 2667385
Adjusted points from 280 to 350
0
 
LVL 2

Accepted Solution

by:
christophm earned 1050 total points
ID: 2670430
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
ID: 2676257
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
ID: 2812714
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

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