Page 1 of 1

#DllLoad proper usage with utility class

Posted: 19 Nov 2020, 10:26
by kczx3
What is the proper usage of #DllLoad in a class that uses a Dll? Especially if you want the consumer to be able to pass the path to the Dll. Are there concerns/issues with calling #DllLoad multiple times with the same Dll?

Re: #DllLoad proper usage with utility class

Posted: 21 Nov 2020, 10:14
by TheArkive
I would think that might depend on the DLL. Is the DLL meant to be loaded into multiple instances of itself?

Hopefully the DLL is documented in a way where it is easy-ish to manage instances (assuming it is meant to be spawned that way). Maybe it's meant to be loaded once, and then a built in function/method would then load another instance?

What's the DLL to be loaded?

Re: #DllLoad proper usage with utility class

Posted: 21 Nov 2020, 10:48
by kczx3
Its Scintilla. So the Dll only needs to be loaded once per AHK process. But I don't think the #DllLoad should be included in the class that wraps the control. I could probably use the asterisk to avoid issues if the class is included more than once. But then the consumer can't provide the path to the Dll.

Re: #DllLoad proper usage with utility class

Posted: 21 Nov 2020, 10:54
by TheArkive
Ah good point.

Funny, i've been thinking of getting back to scintilla myself...

I thought your original script class had a way to pass a specific path already? Any reason in particular why it should be done through #DllLoad?

Code: Select all

__New(gui, opts := "", DllPath := "Scintilla.dll", Style := 0x50010000, ExStyle := 0x200) {
I would think that in the case of a class script, it is more important to rely on the customer know how to use it, more so than "too much dummy-proofing". Unless, i'm missing a finer point..?

Re: #DllLoad proper usage with utility class

Posted: 21 Nov 2020, 20:18
by kczx3
Makes sense. But I think that is sacrificing performance optimizations by calling #DllLoad and calling the functions by name.

Re: #DllLoad proper usage with utility class

Posted: 22 Nov 2020, 01:38
by TheArkive
If you manage to squeeze more performance out of scintilla with any method, I'd be interested :D I still have some experiments to do with custom syntax highlighting.

Re: #DllLoad proper usage with utility class

Posted: 29 Nov 2020, 08:50
by Helgef
You can only load a dll once, if I'm not mistaken (disregarding copies). Using #dllload or LoadLibrary() on the same dll multiple times will not create new "instances" of it.
you want the consumer to be able to pass the path to the Dll.
Is the consumer a programmer using the class or a user of a program?

I think I would design a class/library with the assumption that the programmer using it loads the dll as it prefers. This could also require the programmer to delete a #dllload if it doesn't want to use it ;).

Cheers.