Re: Creating classes via DLL.

From: David Reeve (dree4456_at_big-pond.net.au)
Date: 01/29/04


Date: Thu, 29 Jan 2004 01:39:40 GMT


"Erik Brännlund" <erik.brannlund_nospam_@epl.ericsson.se> wrote in message
news:bv884n$ch7$1@antares.lu.erisoft.se...

[snip]

> What decides where the "class code is allocated". I.e if I use a callback
into
> the main code and ask the procedure to create my class where is this done.
>
> in DLL
>
> Sp := CallBackFunction(ConstCreateSphere);
>
> In what space would that class be created.
>

I seem to remember Bjorge and myself arguing this one out some time ago.
The conclusions I arrived at are as follows. All corrections gratefully
received :-)

Lets say you have a callback function which returns an instance of
TMyClass. The code for the call back is in your main exe, and is compiled
without any knowledge of the code of the dll. Clearly the code of the exe
must contain a definition of what comprises TMyClass or it won't compile.

Now you need to compile another free-standing module which is the dll. If it
is to use a callback similar to that defined in the exe, it likewise needs
to have a definition of TMyClass in order to compile, . And likewise, it is
compiled without any knowledge of the code in the exe.

When the dll calls the callback code, the instance of TMyClass will be
created using the TMyClass definition resident in the exe, and will reside
within the space of the exe. This means the instance will contain a
reference to the VMT that embraces the exe's definition of TMyClass. This
sounds just fine until you consider what happens when the code of the dll
actually attempts to use the instance. Say it calls TMyClass.DoSomething.
This equates to transferring execution to a specific offset into the VMT of
the exe. However, the actual offset applied will be that relevant to the
dll's VMT. If the two class definitions are identical and the languages are
identical in version and type, then this will work, but it is fragile, and
if you must go down this route, then packages are for you. However, if you
want to play with fire, then I recommend looking at Teixeira and Pacheco,
Delphi 4 Developers Guide where they give several examples of accessing
objects across the dll barrier.

Dave



Relevant Pages

  • Re: Appl. Security Problems
    ... When I Release compile the exe and dll' are in one directory on the network. ... the key you use to sign your production assemblies ...
    (microsoft.public.dotnet.security)
  • Re: DLL Woes
    ... How do I get them to display after I "Make" it into an .exe? ... Do you happen to have a check in the Unattended Execution checkbox? ... compile it' ... DLL Hell problems? ...
    (microsoft.public.vb.general.discussion)
  • Re: recognize .Net controls properly and get infos/styles/properties
    ... and convert and compile the source in VS 2005 ... Since the error is not stopping the generation of the .exe and .dll I ... have both .net 1.0 and 2.0 window listed in the treeview. ...
    (microsoft.public.vc.language)
  • wfSpy and VS2005
    ... and convert and compile the source in VS 2005 ... Since the error is not stopping the generation of the .exe and .dll I ... like the author I get an exception for 1.0 controls and 2.0 control ...
    (microsoft.public.dotnet.languages.csharp)
  • PreTranslateMessage in the DLL is not called
    ... In that class there is a PreTranslateMessage method. ... when I compile this class in the Exe. ... compile this class as a DLL and load it dynamically by LoadLibrary and use ...
    (microsoft.public.vc.mfc)