Solved

sharing instance of dll

Posted on 2002-07-02
11
316 Views
Last Modified: 2013-11-25
I have an ActiveX dll where two different projects have references to it. What needs to be done to allow the two projects to share one instance of the dll so as to share the underlying data within the dll too?

Thanks...
0
Comment
Question by:cartti
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 18

Expert Comment

by:mdougan
ID: 7125390
Well, you probably can't do it with a DLL.  A DLL is meant to run in the "process" of the calling program, so, all of the instance's variables are declared within the bounds of the caller.

To get two applications using one component to be able to share data in the component, the component needs to run "out of process".  The usual way of doing this is to turn your Active-X DLL into an Active-X EXE and give the instancing as Global Multi-Use (I believe).

Any global variables that you declare in the DLL should be available to any client who happens to be referencing the Active-X EXE.

Keep in mind, that if no clients have an instance open of the Active-X EXE, then I think that the EXE shuts down (but that might depend on in the instancing... and/or it might be something you can configure).
0
 
LVL 5

Expert Comment

by:rpai
ID: 7125394
I would suggest using Stateful objects (Shared Property Manager, for example) to share the data within the dll. If either of the application that use the Dll component release the reference to the dll, the data will not be available to the other application. So the safest method would be to use stateful objects.
0
 
LVL 2

Expert Comment

by:woka
ID: 7125497
If you use the apartment threading model (set in project properties), anything you declare in a .bas module as Public will be shared between instances of your class.  This is regardless of whether you use a DLL (in process) or an EXE (out of process).

mdougan is almost right.  Each instance of your class will create it's own address space for it's own variables.  But this is only for variables declared as Private to the class.  Anything declared as Public in a .bas module will be shared.

The public data will remain available as long as there is at least one reference to a class in the DLL.  If there are no references (ie. all of your references have been set to =Nothing)  the DLL is unloaded and the data is destroyed.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7125737
Please post a message to Community Support to delete your following open questions:
Retrieving the processes of all Excel applications Date: 02/04/2002 08:56AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20262924
Manipulating folder permissions Date: 09/07/2001 10:06AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20180043
Left, Top properties of form Date: 08/09/2001 01:20PM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20166110
Accessing the call stack Date: 07/05/2001 12:54PM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20146475
Free membership ISP's Date: 07/09/2001 03:31PM PST  
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lounge&qid=20148103
Anthony

0
 
LVL 18

Expert Comment

by:mdougan
ID: 7125860
woka,

admittedly, I am probably wrong about this, but my understanding is that regardless of your threading model, any storage allocated in a DLL is going to be restricted to the process that spawned the DLL.  

Now, if a single project spawns multiple instances of the class in the DLL, I'd agree with you, that those instances could share public variables, because they are all running under the same process.  

However, I would stop short of saying that two separate executables, running in their own processes, instantiating their own instances of a class in a DLL would be able to share public variables.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:woka
ID: 7125983
What is to feel humbled....

Your right.  I just did some tests.  They are only "public" if instances of the class are started in the same executable.  If they are in different executables, the Public vars are only public to the current exe instance.

cartti: Ignore me and listen to a real expert <sigh>
0
 
LVL 2

Author Comment

by:cartti
ID: 7127288
Having done some tests, it doesn't seem to be possible. What I've done is to merge both projects so they use the same dll. It's not ideal, but theoretically it should have been done that way in the first place.

Unless anyone can come up with a solution, I'll delete the question.

Thanks for your contributions.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 135 total points
ID: 7127689
Well, again, converting the DLL to an EXE will do what it is you wanted to do.  I'm not sure why you would choose to merge your two projects and not simply change the project type of your component to Active-X EXE

But, if that's out of the question, then go ahead and delete the question.
0
 
LVL 2

Author Comment

by:cartti
ID: 7127859
mdougan,

The ActiveX exe technique didn't work either.

Regards...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7971260
Hi cartti,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mdougan's comment(s) as an answer.

cartti, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8018798
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

919 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