Reference Caller's Application Variables from DLL

  • Thread starter Thread starter pauld
  • Start date Start date
P

pauld

I want to be able to access some global variables (defined in a
winforms "ApplicationEvents.vb") from a DLL.

I assume I need to pass a reference to the application object to the
DLL. If so, how would I define it in the DLL and how would I set it
in the main app?

Is there some other way to get a reference to the DLL instantiator's
application object from inside the DLL?

Thanks.
 
Declare the global variables as public and shared:

Namespace SomeNamespace
Public Class SomeClassName

Public Shared SomeVariableField As Integer = 3

End Class
End Namespace


Then, inside the DLL access the variables like this:

Dim i As Integer = SomeNamespace.SomeClassName.SomeVariableField
 
Bryan,

Thanks for the response, but I know I'm missing something because I
don't understand how this will work.

I have a winforms project and I declare a class in the project like
this:
Namespace nsGlobal
Public Class clsGlobal
Public Shared PubSharedString As String = "PubSharedString"
End Class
End Namespace

In the winforms project I have a reference to a separate DLL project.

Obviously the winforms app can instantiate a class from DLL to get a
reference to the class in the DLL, but I don't see how a class
*within* the DLL has any kind of a reference to the class from the
winforms app that instantiated the DLL.

Referencing "nsGlobal" from the DLL project tells me that "nsGlobal is
not declared".

I also tried putting the "nsGlobal" namespace in
"Application.vb" (along with the "My" namespace) and that fared no
better.

What fundamental understanding am I missing here?


Thanks.
 
Shared/static constructors and fields/variables are executed or assigned
when the assembly is first loaded into memory.

If you are not able to see nsGlobal in Intellisense, there may be a root
namespace for the DLL that you are omitting. Usually, the root
namespace matches the name of the project unless you renamed the project
after creating it.

--
Bryan Phillips
MCT, MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com
Web Site: http://www.composablesystems.net
 
Back
Top