Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I have a DLL write data to my application's form?

Status
Not open for further replies.

jmk396

Programmer
Dec 30, 2004
1
US

I'm trying to have a DLL write to a Form from inside an application. The way I'm trying to do this is by using a procedural type and then passing it in as a variable to my DLL.

Here are some code snippets:

// [FROM THE APPLICATION .EXE]
type TStrProc = procedure(s : String);
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.

--------------

// [FROM THE DLL]
type TProc = Procedure(s : String);

// ...
procedure DllTest(proc : TProc); stdcall;
begin
proc('This should be displayed on my main application's form.');
end;


--------------

However, when I run this program I am getting an Access Violation (Access Violation at address 008D1AA3. Write of address 0000000000.)

What am I doing wrong?

Thanks,
John
 
I have found that I must allow a lot of extra time in my budget when DLL's are involved, because they are tricky to setup. However, from your code, it looks like you are trying to return a result from the DLL to the calling application. I have never been able to do that. There are probably better programmers than me that have been successful doing that but all I have succeeded in doing is pulling a value out of the DLL. i.e. calling the DLL to perform a task and it returns a value to the calling app. You probably know how to do that and there are several examples on CodeCentral so I won't go into details here.

Good luck

Regards

 
if you want to pass strings between your app and dll, both must use the unit Sharemem (borland's memory manager).
I use fastsharemem as it has the advantage you don't have to include borland's dll in your app (borlndmm.dll).

--------------------------------------
What You See Is What You Get
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top