Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Dynamic Dll - global variable

I am busy coding a dll that supplies several functions to a host application. This application calls the dll dynamically, loading and freeing it after every function call.

I have no control over the host app. I can only work with within the dll. Is there a way I can keep certain variables in memory so that I can reuse them within each function? Obviously a global varable gets cleared when the dll is unloaded by the host app. Saving the dll to file sounds very messy!

Can anyone suggest a way of assigning a variable that i can keep global?

Thanks

like image 394
Crudler Avatar asked Jun 25 '09 07:06

Crudler


1 Answers

I think you have 2 main options here.

  1. offer 2 versions of your function, the one you have now, plus another where they pass in a buffer (record, whatever) that you can read previous state from, and of course update the state into. Call this the high perf version of the function. They will want to use it.

  2. Save the state like you would a cookie (thats basically what it is) in a file somewhere.

Option 1 would require modification to the host app, but would be compelling for the host app developers to take advantage of, Option 2 would require no changes to the host app, but would not be as performant.

I would not personally be inclined to start mucking about with the reference count, presumably the host app is unloading for a reason, if I was the host app dev, that would annoy me.

like image 51
Tim Jarvis Avatar answered Sep 27 '22 19:09

Tim Jarvis