Reference Application Variables Inside 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.



I RECEIVED A PRIOR RESPONSE THAT I DIDN'T UNDERSTAND:
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
 
Paul,

You need to ensure you've added a reference to the assembly that
contains your static/shared property or field variable to the
"project" that will need to use the value. You can do this by
accessing the "References" tab on the project properties screen in
Visual Studio and clicking "Add". Look into "Adding project or
assembly references to projects" on MSDN or the web for more info.

After you add the assembly reference to the project that wants to
reference the variable you then refer to it using a fully qualifed
name as demonstrated in someone's previous response to your original
post. For example:

Dim myLocalString =
MyReferencedAssemblyNamespace.MyClassInThatAssembly.MySharedStringVariable

I believe your problem is largely due to not having the assembly
referenced in your project.

HTH,
Geoff
 
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?

You can't. Anything the dll needs to access will need to be passed into the
dll. You can't pass in an app object because the dll won't know what your
app object is. Something is wrong with your approach, can you give more
details of what you're trying to do.
I RECEIVED A PRIOR RESPONSE THAT I DIDN'T UNDERSTAND:

Whoever wrote this response didn't understand the question (unless it is me
who didn't understand :-)

Michael
 
Back
Top