Module Problem

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

LVL 1
JimGSYAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
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
Erick37Commented:
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
fds_fatboyCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JimGSYAuthor Commented:
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
fds_fatboyCommented:
>>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
JimGSYAuthor Commented:
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
fds_fatboyCommented:
There might be, but without seeing your code - I have trouble visualising exactly what you're doing.
0
JimGSYAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.