2015-09-02 66 views
0

我使用的外部DLL,但我得到這個錯誤外部DLL的Visual Studio C#錯誤

An unhandled exception of type 'System.DllNotFoundException' occurred in ACRCloudExtrTest.exe. Additional information: Unable to load DLL 'acrcloud_extr_windows_1.0.1.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

我已經把項目文件夾中的DLL,也SYSTEM32和SYSWOW64,但毫無效果。

我在這裏調用DLL:

class ACRCloudExtr 
{ 
    public static byte[] CreateFingerprint(byte[] pcmBuffer) 
    { 
     byte[] fpBuffer = null; 
     if (pcmBuffer == null || pcmBuffer.Length <= 0) 
     { 
      return fpBuffer; 
     } 
     IntPtr pFpBuffer = IntPtr.Zero; 
     int fpBufferLen = create_fingerprint(pcmBuffer, pcmBuffer.Length, ref pFpBuffer); 
     if (fpBufferLen > 0) 
     { 
      fpBuffer = new byte[fpBufferLen]; 
      Marshal.Copy(pFpBuffer, fpBuffer, 0, fpBufferLen); 
      free_fingerprint(pFpBuffer); 
     } 
     return fpBuffer; 
    } 

    [DllImport("acrcloud_extr_windows_1.0.1.dll")] 
    private static extern int create_fingerprint(byte[] pcm_buffer, int pcm_buffer_len, ref IntPtr fps_buffer); 
    [DllImport("acrcloud_extr_windows_1.0.1.dll")] 
    private static extern void free_fingerprint(IntPtr fps_buffer); 
} 
+0

與ACRCloudExtrTest.exe位於同一文件夾中的是acrcloud_extr_windows_1.0.1.dll嗎? – Polyfun

+4

它不會告訴你什麼DLL無法找到,只有這個DLL不能*加載*。如果你不知道這個需要的其他DLL,那麼可以使用電話或SysInternals的Process Monitor。 –

+0

是http://prntscr.com/8bt9i0 – user3181034

回答

0

如果你有一個DLL在您的項目中引用右擊它 - >性能 - >複製本地 - >設置爲 。 >性能 - -

否則,如果該DLL是項目文件夾作爲一個DLL文件中把它添加到你的項目,右鍵單擊>複製到輸出目錄 - >設置爲一直拷貝

Build您的項目。

+0

在P/Invoke [DllImport]中使用的DLL似乎不太可能出現在項目的程序集引用列表中(存在混合的非託管/受管DLL的情況,但它們並不常見)。 – stakx

0

- 使用Dependency Walker來檢查您的DLL,以查看它調用的其他DLL。

- 將這些DLL複製到項目輸出文件夾中。他們可能有自己的依賴來解決。