?
Solved

Module Problem

Posted on 2004-11-10
8
Medium Priority
?
169 Views
Last Modified: 2010-05-02
I've made a dll which i want to Create multiple times from another application (it contains information about staff members). Any public variables that i created in the modules are kept when i create the next copy of the dll. How can i keep any public variables created for the DLL unique to that DLL and not open to any other copies i make of it?

Can the DLL be created in a separate memory space each time to stop this from happening? What is happening?

Thanks in advance
Jim

0
Comment
Question by:JimGSY
8 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12547204
can you show some of the code that you are using?  How are you creating multiple instances of your class?

can you show some of the code for the DLL, as well?

AW
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 300 total points
ID: 12547394
Apartment-Model Threading in Visual Basic
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconapartmentmodelmultithreadinginvisualbasic.asp

Read carefully the last section: "Reentrancy"
0
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 1200 total points
ID: 12548864
You cannot safely use public variables in modules inside a COM DLL. These use shared memory even with apartment model threading. The simplest way around this is to create a class from your module and instance per instance of your dll running.

For places you can't avoid using a module, callback dlls (addressOf), You can keep a register of public variables. I have done this with a 2D array with one column as the dll reference key. To get this key, you can instantiate an object and then use the result of objptr().
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:JimGSY
ID: 12553052
That's annoing... Ok, say i created a "global" class from the module, is there then an easy way to allow any other class in the project to access that "global" class? or do i have to pass it between classes using the SET statement?

Arthur_Wood
This was created to run with an intranet, basicly any time someone logged on it created a new copy of the DLL, set which user was logged on and then stored that copy of the DLL in an ASP session. When i created the latest version of the dll (which used standard modules to store the current user,) anyone logged on suddenly found themselves changing which user they were logged on as.
0
 
LVL 10

Assisted Solution

by:fds_fatboy
fds_fatboy earned 1200 total points
ID: 12553181
>>Ok, say i created a "global" class from the module

Hmm that's interesting. I've never tried that. I would assume that if you have a global variable in a module pointing to an instance of a class, you will use the same instance for all instances of the dll. Therefore in effect - shared memory - the same problem. Also - you might have trouble in unloading your dll (again I'm not sure without a lot more thought and possibly some prototyping).

To summarise:
If you want an instance of a dll to own its own properties (variables) that it can change without affecting any other instance of that dll - this data thes properties must reside in a class. That class must must have one instance per instance of the dll. If the properties can be shared across all instances of the dll -  and when you change a property, the property will be changed across all instances, use a variable in a module, scoped at the module level.

The same is true for ActiveX controls - and because of this, subclassing (requires callbacks to a module) can be a lot of fun.
0
 
LVL 1

Author Comment

by:JimGSY
ID: 12553813
Thanks,

I created a class to hold all the variables in the inital class, then passed that from one class to the next using the SET statement. Shame that there is not a better way to acomplish this, however i'm sure there is a valid reason, there normally is.

Thanks for everyone's help
Jim
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12553912
There might be, but without seeing your code - I have trouble visualising exactly what you're doing.
0
 
LVL 1

Author Comment

by:JimGSY
ID: 12555068
I've created a Class called "GlobalProject" Alias "pwv" this contains all the variables that i want to use accross the project. I create a new instance of this in my first class then use the SET statement to pass it to any sub-classes (into a public variable of type "GlobalProject"). Is this the way you'd do it? Infact... does that make sence?

Public Property Get CU() As StaffDetails
    If mStaffDetails Is Nothing Then
        Set mStaffDetails = New StaffDetails
        Set mStaffDetails.pwv = pwv '<------
       
        If pwv.AuditOn Then pwv.AddAudit "Intra", "CU", "Created new CU StaffDetails class"
       
        mStaffDetails.IsCU = True
       
        If pwv.StaffNo <> 0 Then mStaffDetails.StaffNo = pwv.StaffNo
    End If

    Set CU = mStaffDetails
End Property
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

621 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