2017-12-09 19 views
0

일부 클라우드 디렉토리에있는 dll을 랩핑하려고합니다.랩퍼 인터넷의 일부 링크에서 dll을

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); 
} 

나는 DLL 파일의 유효성을 검사하고,하지만 난 사용하는 경우 :

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

그것을 잘 작동합니다.

그러나 사용과 같은 인터넷에서 일부 파일을 경우

는 :

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

작동하지 않습니다.

그런 상황에서 일부 클라우드 드라이브의 DLL 파일을 어떻게 확인할 수 있습니까?

답변

0

LoadLibrary 함수 https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175(v=vs.85).aspx URL이 아닌 파일 경로 만 지원합니다.

그래서 임시 위치로 다운로드하십시오. webclient 클래스를 사용하여 코드에서 수행 할 수도 있습니다. 간단한 예 : https://stackoverflow.com/a/525372/4640588

편집 - 예 경로를 사용하여 당신은 나중에 삭제,

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

그것의 유효성을 검사

를 제공했다.

+0

하늘빛 빛에 대해 생각해보십시오. 임시 위치는 어떻게 될 수 있습니까? – Billy

+0

나는 파일을 tempPath에 다운로드했다. 콘솔 프로젝트에서 실행하면 제대로 작동합니다. 하지만 Azure Function 프로젝트에서이 파일을 실행하면 파일이 LoadLibrary의 "isInvalid"를 반환합니다. – Billy