Hi @ll!
I can't believe, but all my dreams have come true - I found the solution for our problem.
First I have to say, that copying all the libraries to the execution directory is a nasty solution. Especially if you integrate gecko in a third party application.
Ok - here's how it works:
First:
- Identify which libraries xulrunner needs -> (xulrunner directory)
in my case - here are the libraries in my xulrunner directory.
softokn3.dll
AccessibleMarshal.dll
freebl3.dll
IA2Marshal.dll
ssl3.dll
xpcom.dll
js3250.dll
javaxpcomglue.dll
xul.dll
nss3.dll
mozctl.dll
mozcrt19.dll
mozctlx.dll
nssdbm3.dll
nssckbi.dll
nspr4.dll
sqlite3.dll
smime3.dll
nssutil3.dll
plc4.dll
plds4.dll
The key is that you have to load all the libraries dynamically before you call the Initialize() Method.
Do it like this:
Code:
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibraryEx(string dllFilePath, IntPtr hFile, uint dwFlags);
[DllImport("kernel32.dll")]
public extern static bool FreeLibrary(IntPtr dllPointer);
static uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
static uint LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040;
static uint LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008;
public static IntPtr LoadWin32Library(string dllFilePath)
{
try
{
System.IntPtr moduleHandle = LoadLibraryEx(dllFilePath, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH);
if (moduleHandle == IntPtr.Zero)
{
// I'm gettin last dll error
int errorCode = Marshal.GetLastWin32Error();
throw new ApplicationException(
string.Format("There was an error during dll loading : {0}, error - {1}", dllFilePath, errorCode)
);
}
return moduleHandle;
}
catch (Exception exc)
{
throw new Exception(String.Format("Couldn't load library {0}{1}{2}", dllFilePath, Environment.NewLine, exc.Message), exc);
}
}
In my case, I have a list of all DLL I have to load and then I iterate through it and call the LoadLibrary method. I suggesst that you save the IntPtr returned and call FreeLIbrary when you close your application.
The flag 'LOAD_WITH_ALTERED_SEARCH_PATH' is the part that changes the Windows Search order.
The cool thing is, that windows continues with the default search order (system32, system, windows, path), if the specified dll cannot be found.
Hope this helps you
best
peter