On Wed, Mar 15, 2017 at 4:42 PM, Raffaello Giulietti <raffaello.giulietti@lifeware.ch> wrote:
Hi Ben,

my understanding is that SetDllDirectory only affects the search path of libraries that are loaded at *run-time* with LoadLibrary.

What I'm asking for is a mechanism that works at *load-time*, when a library I'm accessing directly depends on another one which I'm not targeting directly.

I don't quite follow.�� I'm not intimate with Windows dynamic loading, so these questions are an opportunity for me to learn...��

You can't mean when Pharo loads, because it wouldn't know of OTHER.DLL ?
���� ��
Do you mean that LoadLibrary is not called explicitly by YOUR.DLL before its uses the function from OTHER.DLL? ��

Do you mean you link OTHER.DLL to YOUR.DLL at compile time? ��
But still, YOUR.DLL it not loaded until called via Pharo FFI, so neither is OTHER.DLL,
and��Dynamic-Link Library Search Order [1] says... "If a DLL with the same module name��
is already loaded in memory, the system uses the loaded DLL, no matter which directory it is in.��
The system does not search for the DLL."

So maybe before calling any of YOUR.DLL,
do a SetDllDirectory followed by a LoadLibrary(OTHER.DLL)��
and later when you call into YOUR.DLL,��
OTHER.DLL is already loaded.

Otherwise it would seems(?) your options are either Manifests
or Dynamic-Link Library Redirection, both done outside of Pharo.
��
[1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx��
��
cheers -ben


But I'll try whether SetDllDirectory also affects load-time searches.

Anyway, I hope future versions of the UFFI to offer setting the search paths more easily.



Greetings
Raffaello




On 2017-03-15 07:22, Ben Coman wrote:


On Tue, Mar 14, 2017 at 11:23 PM, Raffaello Giulietti
<raffaello.giulietti@lifeware.ch
<mailto:raffaello.giulietti@lifeware.ch>> wrote:

�� �� Hi,

�� �� say I want to directly use a library that depends on other libraries
�� �� in different folders. How does UFFI proceed to find these other
�� �� libraries?

�� �� Is there a way to specify the search folders in UFFI?

�� �� I'm on Windows and in Pharo5/6.

�� �� Greetings
�� �� Raffaello


I assume you mean specifying the search path outside of Pharo.
Perhaps call�� SetDllDirectory�� via Pharo FFI.
(YMMV disclaimer, my knowledge of this is a few minutes searching)

SetDllDirectory function
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686203(v=vs.85).aspx

LoadLibrary function
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx

Dynamic-Link Library Search Order
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx

cheers -ben