Re: How can I have a DLL write data to my application's form? (eg. DLLs and procedural type question)

From: Rob Kennedy (me3_at_privacy.net)
Date: 12/31/04


Date: Thu, 30 Dec 2004 17:19:05 -0600

jklimek@gmail.com wrote:
> // [FROM THE APPLICATION .EXE]
> type TStrProc = procedure(s : String);

Did you remember to use the ShareMem unit in both the DLL and the EXE?
There was a comment explaining that at the top of your new DLL project.

> type TProc = procedure(proc : TStrProc);
> var DllTest : TProc;
>
> // eg. load the library, etc, etc...
> // ...
>
> @DllTest := GetProcAddress(LibHandle, 'DllTest');
>
> // ...
> DllTest(@DisplayIt); // this should pass the address of my local
> procedure (DisplayIt) to the DLL.

Do you really mean *local* procedure? That's another name for a nested
procedure, and you're not allowed to use pointers to those since they
need to be called specially; the place you send the pointer won't know
how to call the nested procedure pointer.

> // [FROM THE DLL]
> type TProc = Procedure(s : String);
>
> // ...
> procedure DllTest(proc : TProc); stdcall;

A-ha. Here you've declared the procedure as stdcall. In your EXE, you
did not specify a calling convention, so Delphi assumed you wanted the
register calling convention. The two are not compatible. The
declarations of the functions in both modules need to match.

(It also helps your sanity if you use the same type names in both
places. You declared the callback function type as TProc in the DLL, but
you named it TStrProc in the EXE. Pick a real, meaningful name, and use
it throughout.)

-- 
Rob


Relevant Pages

  • Re: Editors
    ... some strip them on exe files by default. ... "preferred base address" and, yup, relocations are completely ... DLL files, though, aren't loaded into their own address space but are ... EXE's "entry-point", though, is not "special" in that it's just an ...
    (alt.lang.asm)
  • Re: new - delete issue
    ... EXE calls a DLL exported function that return a struct pointer. ... The EXE call another exported function that delete all pointers in that list. ...
    (microsoft.public.vc.mfc)
  • Re: DLL pass vector by value crash
    ... The prototype for testfunc is a by-value copy, so it has to make a copy of the value. ... Are you using static linking for either the .exe (if so, it probably won't work correctly, ... clearly using the shared CRT DLL for the DLL you are constructing. ... no crash occurs in either config. ...
    (microsoft.public.vc.mfc)
  • Re: DLL pass vector by value crash
    ... stack of the exe and may allocate default member element on the exe heap. ... If this is a dangerous situation, the simple app I set up calling testFunc() ... in a dll did not crash. ... msvcr90.dll!free and access the source code of free.c. ...
    (microsoft.public.vc.mfc)
  • Re: Releasing my VB.NET app over the intranet
    ... of the primary EXE and when compiled I am copying the contents ... the directory and open a browser on the web server and type ... > another dll, we need to put the dll in the same directory, so that the clr ... > The executable will be downloaded to the assembly download cache on the ...
    (microsoft.public.dotnet.framework)