Re: Creating classes via DLL.
From: David Reeve (dree4456_at_big-pond.net.au)
Date: 01/29/04
- Next message: David Reeve: "Re: Converting C++ header file to Delphi4 pas unit"
- Previous message: VBDis: "Re: Data Type Converter"
- In reply to: Erik Brännlund: "Re: Creating classes via DLL."
- Next in thread: AlanGLLoyd: "Re: Creating classes via DLL."
- Reply: AlanGLLoyd: "Re: Creating classes via DLL."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: David Reeve: "Re: Converting C++ header file to Delphi4 pas unit"
- Previous message: VBDis: "Re: Data Type Converter"
- In reply to: Erik Brännlund: "Re: Creating classes via DLL."
- Next in thread: AlanGLLoyd: "Re: Creating classes via DLL."
- Reply: AlanGLLoyd: "Re: Creating classes via DLL."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|