Chet icon indicating copy to clipboard operation
Chet copied to clipboard

Support for dynamic loading ?

Open EricGrange opened this issue 1 year ago • 7 comments

Current headers are converted to static bindings (with optional "delayed").

Would it be possible to have an option to generate dynamic bindings instead ? (with GetProcAddress, etc)

The use case would not be just to survive a dll not being present, but also allow the dll name and path to be specified.

EricGrange avatar Sep 11 '24 07:09 EricGrange

Click the post process button and click the help. I added a PP command to do just that. I hope to submit a PR at some point with all my fixes and enhancements since the last update. Sorting through some corner cases.

jarroddavis68 avatar Sep 11 '24 07:09 jarroddavis68

@jarroddavis68 yes, that's one way I was looking at it (but doing it directly in small Delphi executable) Did you publish your PP command ?

EricGrange avatar Sep 11 '24 08:09 EricGrange

image CreateDynamicImport(0) this post processing command will create: image

image

then you can call GetExports in your own code to dynamically load. This is in now. You will run into a few issues that a future PR will address, but it does work.

jarroddavis68 avatar Sep 11 '24 08:09 jarroddavis68

Thanks!

FWIW use case is for webgpu.h (https://github.com/EricGrange/Delphi-WebGPU) where you have several implementations, and each implementation regularly churns out builds, so plenty of "compatible" dlls to choose from :)

EricGrange avatar Sep 12 '24 07:09 EricGrange

Hmm, the "CreateDynamicImport(0)" in Post process doesn't seem to have any effect ? Though I'm not even sure the post process script is executed at all (a lone SaveToFile doesn't create anything AFAICT and there is no error when placing garbage in the pp script)

EricGrange avatar Sep 12 '24 08:09 EricGrange

post processing will effect this output: image

here is a build with all the PP changes I've made since the release that you have: Chet.zip | VirusTotal Report

So, the script processing is basic, enough to get the job done. If the script command is mispelled and/or not in the correct format, it will just be silently ignored. For example, if you add a ; at the end, like I tend to do at times, that command will be ignored. So, if it does not seem to be working, check the syntax and make sure it's correct.

jarroddavis68 avatar Sep 12 '24 16:09 jarroddavis68

@jarroddavis68 with your build this worked, thanks.

As a small side-request, maybe the post-processing should appear in the translate log ? Currently it's not mentioned, and if the PP script contains invalid commands, there is no error reported either.

EricGrange avatar Sep 13 '24 05:09 EricGrange