Board index » delphi » DLL call a function in the calling app?
cra...@rebic.co.uk (Craig Lister)
![]() Delphi Developer |
Tue, 28 Sep 2004 16:28:35 GMT
|
cra...@rebic.co.uk (Craig Lister)
![]() Delphi Developer |
Tue, 28 Sep 2004 16:28:35 GMT
DLL call a function in the calling app?
Is it possible for a DLL to call a function in a calling application?
For example, the code to read and write to a com port is in the DLL. When something arrives at the port, the DLL has to decode the message, and send it to the calling app. Possible? |
Maarten Wiltin
![]() Delphi Developer |
Tue, 28 Sep 2004 17:14:14 GMT
Re:DLL call a function in the calling app?QuoteCraig Lister wrote in message Quote>Is it possible for a DLL to call a function in a calling application? idea is that the calling program supplies the DLL with a function pointer to call in response to a certain event (like data received on the COM port). The issues are exactly the same as when a program calls an What you could do is define a variable in the DLL to hold This is borrowed shamelessly from the Delphi event construction, Groetjes, [0] Because you can't reach variables in a DLL from the calling |
Smol
![]() Delphi Developer |
Tue, 28 Sep 2004 20:11:11 GMT
Re:DLL call a function in the calling app?Quote"Maarten Wiltink" <maar...@kittensandcats.net> wrote in message Quote> Craig Lister wrote in message a dll. Will loading this app module from the dll start another copy of the app? |
Maarten Wiltin
![]() Delphi Developer |
Tue, 28 Sep 2004 20:44:36 GMT
Re:DLL call a function in the calling app?QuoteSmola wrote in message ... functions, I believe Windows does not let you import them. Of course, a "program" is no different from a DLL with a You could try this mechanism by writing most of your app Groetjes, |
Craig List
![]() Delphi Developer |
Tue, 28 Sep 2004 21:48:49 GMT
Re:DLL call a function in the calling app?Thanks Maarten. I'm trying to do what you say, but am sticking! Unfortunaltly, there Can you maybe see where I am going so wrong: Application Code Snippets: I have simply declared a normal procedure in my APPLICATION called procedure TForm1.GetData; This is probably and most certainly all wrong! I call the DLL, I use procedure TForm1.btnPurgeClick(Sender: TObject); CallBackProc := addr(TForm1.GetData); However, I get NO access violations yet. Good start? Now we go to the DLL code. I have declared a function in the DLL like this: Procedure SendDataToApplication (InData : String ); I also create a variable in the DLL like this: var In this procedure, I'm hoping to send any data captured at the port, In the function that the App calls, this is it here: function Purge (CallBack : TProcedure): Integer; stdcall; Still, no access violations, so maybe not as wrong as I think! However, later in this Purge function, at the end, I do this: CallBackFuntion; ACCESS VIOLATION! Can you see what I am doing wrong here?? Quote"Maarten Wiltink" <maar...@kittensandcats.net> wrote in message <news:a968h7$7u0$1@news1.xs4all.nl>... |
AlanGLLo
![]() Delphi Developer |
Wed, 29 Sep 2004 00:05:44 GMT
Re:DLL call a function in the calling app?In article <84cc68cf.0204120548.7fe71...@posting.google.com>, Quotecra...@rebic.co.uk (Craig Lister) writes: callback. What you have provided is the address of a class or "template" reference. You have a created instance (maybe Form1) of your class. So an actual reference Personally I would tend to use a simple procedure rather than a method, and get MS APIs often take a DWord as an "instance" and return that value unchanged as This is an Audio Compression Manager enumeration call, passing a callback acmDriverEnum(DriverEnumProc, integer(Self), ACM_DRIVERENUMF_DISABLED); This is the callback function which is called from the API with the returned function DriverEnumProc(hACMDrvId : HACMDRIVERID; This is the header for the method ... procedure TForm1.ACMEnumDrvrMethod(hACMDrvId : HACMDRIVERID; fdwSupport Alan Lloyd |
Maarten Wiltin
![]() Delphi Developer |
Wed, 29 Sep 2004 19:47:26 GMT
Re:DLL call a function in the calling app?QuoteCraig Lister wrote in message Quote>Thanks Maarten. is a procedure _in the context of a given object_, which is passed in as the first, implicit, parameter "Self". The value of the expression "Form1.GetData" (or indeed Quote>This is probably and most certainly all wrong! I call the DLL, I use a 32-bit pointer to the start of the code; there is no need to introduce an extra level of indirection. Quote> ErrorCode : Integer; used as the address of a procedure. This is an implicit cast; without wanting to you've worked around your mistake. Quote> memo1.lines.add ('Sending PURGE request to DLL.'); Frankly, I lost track. I don't know any more where all those pointers point. Quote>end; errors is a good start, certainly. A prerequisite, really. - Hide quoted text - - Show quoted text - Quote>Now we go to the DLL code. Quote>var did something wrong. Quote>Still, no access violations, so maybe not as wrong as I think! that contains a pointer to a procedure. Or perhaps to a variable that contains yet another pointer to a procedure; as I said, I lost count. You should be able to get it right the next time, but there's Groetjes, |
1. DLL calling a function in the calling EXE
2. Calling a function in main app from a DLL
3. Questions about calling a DLL functions and shellnotifyicon() function
4. Pointer to a function or call a function inside EXE from a DLL
5. dll error from call in Borland app but not Visual C++.NET app
6. Calling codebase dll functions from another dll
7. Help: Calling Functions Inside DLL from the same DLL
8. calling form in dll from function in dll