Skip to main content
朵格Dolag
Inspiring
January 30, 2023
Answered

An elegant way to allow aex to load DLLs under custom paths

  • January 30, 2023
  • 3 replies
  • 837 views

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".

This topic has been closed for replies.
Correct answer 朵格Dolag

Seems that the group policy may affect this, I have never thought of that. 

3 replies

Mylenium
Legend
January 30, 2023

It probably falls apart on a restricted system where the default DLL load policy is overridden by a group policy setting or paths can't be manipulated in user space.

 

Mylenium 

朵格Dolag
朵格DolagAuthorCorrect answer
Inspiring
January 30, 2023

Seems that the group policy may affect this, I have never thought of that. 

朵格Dolag
Inspiring
January 30, 2023

oh I forgot to return true at the end of DllMain. 

Legend
January 30, 2023

Wow!  I have searched for an answer to this for quite some time.  Thank you for sharing the implementation!  I also do not think it's best practice to place third-party dll files in the host app directory, but couldn't figure it out.  I will need to test out your findings, but could be a while.  Thanks again for sharing this!