Link to home
Start Free TrialLog in
Avatar of djelescu
djelescu

asked on

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

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
Avatar of djelescu
djelescu

ASKER

Adjusted points from 200 to 250
   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
...um what?
Adjusted points from 250 to 270
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.
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.
Adjusted points from 270 to 280
tdubroff-
Thanks for the tip!
I wil post anything I learn from dbox.
Regards,
-Diana
Adjusted points from 280 to 350
ASKER CERTIFIED SOLUTION
Avatar of christophm
christophm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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