Re: Accessing global variables in EXE from DLL

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 05/19/04


Date: Wed, 19 May 2004 18:23:07 -0400

No. And it would be a truly lousy idea to try to do so. The word "Modularization" comes to
mind.

You could pass pointers to these variables in, but frankly, it strikes me as exceptionally
poor practice to do so. If the DLL needs state, the state should come in via a pointer to
some class that defines the DLL context.

The usual reason for this question, by the way, is most often trying to partition
poorly-written code into a DLL, where the poorly-written code uses global variables. The
way to tell it is poorly-written is that, guess what, it accesses global variables.
Putting the code in a DLL just makes the defect obvious.
                                joe

On 19 May 2004 12:24:05 -0700, abhi_junk@hotmail.com (Abhijit Patait) wrote:

>Is there any way I can access the global variables declared in the EXE
>file from a DLL?
>
>Thank you
>Abhijit

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



Relevant Pages

  • Re: C# access to C DLL
    ... >> I'm doing this via an outer DLL that wraps the old C DLL in an unmanaged ... >My guess is that you are passing un-pinned pointers to unmanaged code. ... your comment about pinning pointers may well be the main problem. ... Any recommended references that address this directly? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Call to absolute address
    ... But having to lug around a whole DLL ... > It's basically a simple jump table. ... The rest are pointers to various structures or data. ... > I'm not familiar with vtables. ...
    (microsoft.public.vb.general.discussion)
  • Re: C# access to C DLL
    ... >> I'm doing this via an outer DLL that wraps the old C DLL in an unmanaged ... >My guess is that you are passing un-pinned pointers to unmanaged code. ... your comment about pinning pointers may well be the main problem. ... Any recommended references that address this directly? ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Handle pointers from delphi client to a vb.net dll
    ... I have one dll written in vc++ which uses pointers to handle those ... You have a Web service which should be called from your VB .NET DLL ... your Delphi client "speak" .NET or COM? ... Voodoo Programming: Things programmers do that they know shouldn't work ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Singleton Objects and Heap Allocation
    ... > I'm working in an existing custom framework and a class in that framework allows me to create an object that is a map of name to object pairs. ... You would probably need to tell DLL to use the process' data segment. ... of passing the actual data pointers. ...
    (microsoft.public.vc.language)