Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

Reference Caller's Application Variables from DLL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pauld@maronsoftware.com - 05 Jun 2007 23:33 GMT
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.
Bryan Phillips - 06 Jun 2007 02:49 GMT
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 Phillips
MCT, MCSD, MCDBA, MCSE
Blog:  http://bphillips76.spaces.live.com
Web Site:  http://www.composablesystems.net

> I want to be able to access some global variables (defined in a
> winforms "ApplicationEvents.vb") from a DLL.
[quoted text clipped - 7 lines]
>
> Thanks.
pauld@maronsoftware.com - 07 Jun 2007 18:26 GMT
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.

On Jun 5, 6:49 pm, "Bryan Phillips"
<bphill...@nospam.spamcop.net.spammenot> wrote:
> Declare the global variables as public and shared:
>
[quoted text clipped - 33 lines]
>
> - Show quoted text -
Bryan Phillips - 16 Jun 2007 23:50 GMT
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

> Bryan,
>
[quoted text clipped - 66 lines]
> >
> > - Show quoted text -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.