0

I am trying to wrapper a dll that are in some cloud directory.

 private SafeLibraryHandle sevenZipSafeHandle;

 public SevenZipHandle(string sevenZipLibPath)
    {
        this.sevenZipSafeHandle = Kernel32Dll.LoadLibrary(sevenZipLibPath);
        if (this.sevenZipSafeHandle.IsInvalid)
        {
            throw new Win32Exception();
        }
  }
}

 internal static class Kernel32Dll
{
    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    internal static extern SafeLibraryHandle LoadLibrary([MarshalAs(UnmanagedType.LPTStr)] string lpFileName);

    [DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
    internal static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, [MarshalAs(UnmanagedType.LPStr)] string procName);

    [SuppressUnmanagedCodeSecurity]
    [DllImport("kernel32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern bool FreeLibrary(IntPtr hModule);
}

I am validating a dll file, but if I use :

sevenZipLibPath  = “c:/temp/file.dll”

it works fine.

But if use some file that is on the internet like:

sevenZipLibPath  = “"http://any.blob.core.windows.net/files/file.dll”

it does not work.

How can I check a DLL file from some cloud drive in that situation?

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Billy
  • 1

1 Answers1

0

The LoadLibrary function https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx Only supports filepaths, not urls.

So download it first to a temporary location. You can also do that in code using the webclient class. A simple example: https://stackoverflow.com/a/525372/4640588

Edit - Example using the paths you provided

using (WebClient client = new WebClient())
{
    client.DownloadFile(
        "http://any.blob.core.windows.net/files/file.dll", 
        "c:/temp/file.dll");
}

Validate it, then delete it afterwards.

MrMikeJJ
  • 114
  • 1
  • 4
  • Thinking about an azure function. How could be the that temporary location? – Billy Dec 09 '17 at 15:02
  • I did that downloading the file to a tempPath. If I run it in a console project it works fine. But if I run that in the Azure Function project, the file return "isInvalid" from LoadLibrary. – Billy Dec 09 '17 at 17:09