Login / Register  0 items | $0.00 New What is KVR? Submit News Advertise
No_Use
KVRAF
 
2107 posts since 13 Mar, 2004

Postby No_Use; Sun Mar 05, 2017 7:23 am dynamically linking libsndfile (Windows)

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.
stratum
KVRian
 
955 posts since 29 May, 2012

Postby stratum; Sun Mar 05, 2017 7:39 am Re: dynamically linking libsndfile (Windows)

Have a look at thishttps://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.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~
Mayae
KVRist
 
483 posts since 1 Jan, 2013, from Denmark

Postby Mayae; Sun Mar 05, 2017 7:43 am Re: dynamically linking libsndfile (Windows)

This thread might also be of interest:

viewtopic.php?p=6135556#p6135556
Miles1981
KVRian
 
1128 posts since 26 Apr, 2004, from UK

Postby Miles1981; Sun Mar 05, 2017 7:51 am Re: dynamically linking libsndfile (Windows)

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).
No_Use
KVRAF
 
2107 posts since 13 Mar, 2004

Postby No_Use; Sun Mar 05, 2017 8:14 am Re: dynamically linking libsndfile (Windows)

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 ?
Miles1981
KVRian
 
1128 posts since 26 Apr, 2004, from UK

Postby Miles1981; Sun Mar 05, 2017 8:21 am Re: dynamically linking libsndfile (Windows)

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.
No_Use
KVRAF
 
2107 posts since 13 Mar, 2004

Postby No_Use; Sun Mar 05, 2017 8:29 am Re: dynamically linking libsndfile (Windows)

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.)
Miles1981
KVRian
 
1128 posts since 26 Apr, 2004, from UK

Postby Miles1981; Sun Mar 05, 2017 8:37 am Re: dynamically linking libsndfile (Windows)

Well, in that case, just make your plugin GPL.
No_Use
KVRAF
 
2107 posts since 13 Mar, 2004

Postby No_Use; Sun Mar 05, 2017 8:40 am Re: dynamically linking libsndfile (Windows)

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).
Miles1981
KVRian
 
1128 posts since 26 Apr, 2004, from UK

Postby Miles1981; Sun Mar 05, 2017 10:32 am Re: dynamically linking libsndfile (Windows)

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.
No_Use
KVRAF
 
2107 posts since 13 Mar, 2004

Postby No_Use; Mon Mar 06, 2017 6:35 am Re: dynamically linking libsndfile (Windows)

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:
stratum
KVRian
 
955 posts since 29 May, 2012

Postby stratum; Mon Mar 06, 2017 2:40 pm Re: dynamically linking libsndfile (Windows)

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~
camsr
KVRAF
 
6435 posts since 16 Feb, 2005

Postby camsr; Mon Mar 06, 2017 3:34 pm Re: dynamically linking libsndfile (Windows)

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 ... 97(v=vs.85).aspx
Image
No_Use
KVRAF
 
2107 posts since 13 Mar, 2004

Postby No_Use; Tue Mar 07, 2017 6:56 am Re: dynamically linking libsndfile (Windows)

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.
User avatar
BlitBit
KVRist
 
120 posts since 28 Nov, 2013, from Germany

Postby BlitBit; Fri Mar 10, 2017 11:22 am Re: dynamically linking libsndfile (Windows)

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!
Next

Moderator: Moderators (Main)

Return to DSP and Plug-in Development