An elegant way to allow aex to load DLLs under custom paths
Hi guys,
We developers used to be very troubled by the problem of loading dlls, that we have to put our dlls referenced by our plugins into "Support Files", which is absolutely troublesom. But I found a relatively elegant way to solve this problem in Windows.
To do this, we need to know two things about the plugin loading order.
The first is about the scanning order. I tested some kind of plugin name, and got a result that '$' > '%' > '0'-'9' > '' > '^' > '_' > '{', so for example, the order to load is "$foo.aex" > "%foo.aex" > "0foo.aex" > "9foo.aex" > "foo.aex" > "^foo.aex" > "_foo.aex" > "{foo.aex". The rule above treats files and directories as the same, so when scanning a directory AE will dive in and continue scanning items under that folder.
Second, AE loads plugins under "MediaCore" first and then "Plug-ins".
So the solution is, build a plugin that sets the custom dll search path into environment variable "PATH" in the DllMain function which is called on load, and use rules above to make sure this dummy plugin loads before your real plugin, that's much nicer than just dropping dlls into "Support Files" ahh.
The DllMain function can be defined as below:
// DllMain is called on load from process or thread
BOOL WINAPI DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
) {
// set env when loaded for process_attach
// not thread_attach
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
_wputenv_s("PATH", LR"(C:\your\dll\folder)"); // set envienoment
return true;
}
}
The last question is how to hide this plugin. You can simply set the "Kind" property to "AEGP" in PiPL to prevent it from being searched, so I recommend you build this dummy plugin based on the AEGP sample project, like "ProjDumper".
