Board index » delphi » Object references and dll's in Delphi1

Object references and dll's in Delphi1

I have been trying to do some manipulations on objects passed (as reference)
from an exe to a dll. Sometimes this works, sometimes it doesn't.
After digging in some articles on Compuserve and such, I have understood
that a virtual method can cause problems in Delphi1 when called from a dll,
if the object was created in the exe ( and vice versa ).

To give an example of some funny things that happen.

in the exe :
...
aBitmap := TBitmap.Create;
DllFunction( aBitMap, par1 , par2 );
...

in the dll :

function DllFunction( aBItmap : TBitmap ; par1,par2 : integer ) :
TMemorystream;
begin
    ...
    DoSomeThingWith( aBitmap.Handle );
    ...
end;

This worked fine when the declaration of the function looked like this :
function DllFunction( aBitmap : TBitmap ) : TMemorystream;
Also with the new declaration everything works fine when you step through
the code with the de{*word*81} (the exe code of course).
But when you run outside of the IDE there is an access violation when you
try to do something with the handle.
When I compiled all the code into the exe everything worked fine also.
My guess is that it has something to do with the stack. It is the only thing
that was different in all those cases.

To cut a long story short : does anybody have any suggestions on what to do
with this ??

 

Re:Object references and dll's in Delphi1


On Wed, 4 Mar 1998 17:48:04 +0100, "CDS personal account"

Quote
<development-...@pophost.eunet.be> wrote:
>I have been trying to do some manipulations on objects passed (as reference)
>from an exe to a dll. Sometimes this works, sometimes it doesn't.
>After digging in some articles on Compuserve and such, I have understood
>that a virtual method can cause problems in Delphi1 when called from a dll,
>if the object was created in the exe ( and vice versa ).

It's not just virtual methods, but any method that is not declared with the
EXPORT directive. Instead of passing TBitmap objects to and from a DLL, pass
Windows HBITMAP handles, and recreate the necessary TBitmap objects.

--
Ray Lischner (http://www.tempest-sw.com/)
Author of "Hidden Paths of Delphi 3: Experts, Wizards, and the Open Tools API"

Other Threads