dynamically linking libsndfile (Windows)

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

My plugin uses the libsndfile library which I have dynamically linked.

The plugin runs fine when libsndfile-1.dll is present in the Windows system folder but not when I try to put it in the same folder the plugin is residing (and not present in system folder).

Is there a way I can make the plugin look for the libsndfile-1.dl in its own folder first and load from there if present (if so, how) ? I'm using Visual Studio for developing.

Post

Have a look at thishttps://msdn.microsoft.com/en-us/librar ... s.85).aspx

If the information implies that it won't work for your case, you can always use LoadLibrary and GetProcAddress methods and give a full module path to LoadLibrary call.
~stratum~

Post

This thread might also be of interest:

viewtopic.php?p=6135556#p6135556

Post

You should probably link it statically, not dynamically. Even if it's because of the license.

The option of delaying loading the library is the only way it can work otherwise. Then indeed, either you load it explicitly and get the functions out of the library yourself (don't forget to free loading the library...) or you can try lazy-loading, as then the runtime will load the missing pieces when they are first accessed (then you probably want to force looking for all libsndfile functions in the constructor so that you don't get hit in the processing function if that's where you are using it).

Post

Useful info.

Reading through the MS link, first search location is "The directory from which the application loaded.", so I figured I can put the .dll where the host/DAW is installed and it works.

That's good enough for my case (less intrusive than putting it in system folder), thank you.

@ Miles
Thanks also, but statically linking is indeed not possible because of the license here.
The option of delaying loading the library is the only way it can work otherwise.
Hm...first tests seem to work fine putting it where the host/DAW is, could I run into trouble doing it this way then ?

Post

The issue is that you may not have access to the location of the host. When users install your plugin, they may not have administrative rights, so don't count of this to work in the general case.

Post

Miles1981 wrote:The issue is that you may not have access to the location of the host. When users install your plugin, they may not have administrative rights, so don't count of this to work in the general case.
Ah yes, true.
But to give some background why I'm asking:

I do a little freeware plugin I don't want to do an installer for (just d'n'd the plugin in the plugins folder).
For this I think it's fine telling the user "if host complains during scan that libsndfile is not found, download from meganerd and put in your host install directory", a lot of users would probably hesitate putting the .dll in system folder though I'd imagine so I was looking for an (easy) alternative.

I think I'll go with this option then (if users can't be bothered doing this small extra step ah well so be it then.)

Post

Well, in that case, just make your plugin GPL.

Post

Obvious option, sure. :D
But I'm just doing the Win port of a plugin, so I have no influence on the license of the original code (which is not my own code).

Post

In that case, as it's a freeware, you should ask for a change in the license. Having to add a library by hand in the hostS folder (for each host you have) is quite a big issue. Not sure if the guy that made you do the port wanted that kind of hassle for his user and the bad publicity associated with that kind of issue.

Post

The license of the code is currently reflected.

But in case I have to go the 'link dynamically' route (i.e. it doesn't become GPL) could someone help me out doing this in a WDL/iPlug project ?

I gues I need to:
- do an installer which installs the libsndfile-1.dll besides the plugin (save way would be installing it in system folder but that's not a good practice at all I think). This step shouldn't be a problem as iPlug contains installer scripts.
- change the .dll search path so it's looking in the install folder first and 'lazy load' it

I checked out the thread linked above which gives hints (viewtopic.php?p=6135556#p6135556) but this involves modifying the VST SDK I think which I'd rather refrain doing, if possible.

btw., in case someone's wondering (and to adress Mile's reply above), this is not a contract porting work or something, just a personal learning project, that's why I come up with those rather noobish questions. :oops:

Post

Look for LoadLibrary call in WDL-OL, probably there is a wrapper in it that does the following in a portable way:

Code: Select all

HMODULE hmod =NULL;

typedef int signature_of_the_method_of_interest(int args);
signature_of_the_method_of_interest* pmethod=NULL;

void free_libs()
{
	if(hmod)
		FreeLibrary(hmod);
}

atexit(free_libs);

hmod =LoadLibrary("full path to libsnd.dll");
if (hmod)
{
	pmethod = (signature_of_the_method_of_interest* )GetProcAddress(hmod,"name of the method");
}


// how to use

(*pmethod ) (args_of_interest);
~stratum~

Post

You could attempt to find the path of the active plugin DLL first, then use that to load the auxillary DLLs.
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Post

camsr wrote:You could attempt to find the path of the active plugin DLL first, then use that to load the auxillary DLLs.
I think I'll probably go this route, that's what I also found recently and it seems to work.
http://stackoverflow.com/a/6924332

Thanks.

Post

No_Use wrote:
camsr wrote:You could attempt to find the path of the active plugin DLL first, then use that to load the auxillary DLLs.
I think I'll probably go this route, that's what I also found recently and it seems to work.
http://stackoverflow.com/a/6924332

Thanks.
If you are using WDL-OL/IPlug you can also use the method IGraphics::PluginPath. More info here:
viewtopic.php?p=6583690

Good luck!
Passed 303 posts. Next stop: 808.

Post Reply

Return to “DSP and Plugin Development”