Programming

DLL을로드 할 수 없습니다 (모듈을 찾을 수 없음 HRESULT : 0x8007007E).

procodes 2020. 8. 13. 20:50
반응형

DLL을로드 할 수 없습니다 (모듈을 찾을 수 없음 HRESULT : 0x8007007E).


내 .NET 4.0 응용 프로그램에서 사용해야하는 관리되지 않는 C ++ API 코드가있는 dll 라이브러리가 있습니다. 하지만 내 DLL을로드하려고하는 모든 방법에 오류가 발생합니다.

DLL 'MyOwn.dll'을 (를)로드 할 수 없습니다 : 지정된 모듈을 찾을 수 없습니다. (HRESULT 예외 : 0x8007007E)

나는 인터넷에서 찾은 severa 솔루션을 읽고 시도했습니다. 작동하지 않습니다 ..

다음 방법을 사용해 보았습니다.

[DllImport("MyOwn.dll",  CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs((UnmanagedType.I4))]
public static extern Int32 MyProIni(string DBname, string DBuser_pass,
    string WorkDirectory, ref StringBuilder ErrorMessage);

이 기사를 따르고이 예제를 실행하면 (다운로드 된 코드에서) 문제없이 실행됩니다 (사용 된 dll은 bin / debug 폴더에 있음).

내 dll을 복사했습니다 (모든 파일과 함께 내 bin 폴더에 의존합니다).

나는 또한이 접근 방식을 시도했지만 동일한 오류가 발생했습니다.

[DllImportAttribute(MyOwnLibDllPath, EntryPoint="TMproIni")]
[return: MarshalAs(UnmanagedType.I4)]
public static extern  int MyproIni(string DBname, string DBuser_pass, 
    string WorkDirectory, ref StringBuilder ErrorMessage);

어떤 제안?


Windows에서 기억하는 dll 검색 순서는 다음과 같습니다.

  1. 현재 디렉토리
  2. 시스템 폴더 C:\windows\system32 or c:\windows\SysWOW64(64 비트 상자의 32 비트 프로세스 용).
  3. Path환경 변수 에서 읽기

또한 DLL의 종속성을 확인하고 Visual Studio와 함께 제공되는 종속성 워커가 여기에서 도움을 줄 수 있으며 무료로 다운로드 할 수도 있습니다. http://www.dependencywalker.com


dumpbin 도구를 사용하여 필요한 DLL 종속성을 찾을 수 있습니다.

dumpbin /DEPENDENTS my.dll

이렇게하면 DLL이로드해야하는 DLL을 알 수 있습니다. 특히 MSVCR * .dll을 찾으십시오. 올바른 Visual C ++ 재배포 가능 패키지가 설치되지 않은 경우 오류 코드가 발생하는 것을 보았습니다.

Microsoft 웹 사이트에서 "Visual Studio 2013 용 Visual C ++ 재배포 가능 패키지"를 얻을 수 있습니다. c : \ windows \ system32 \ MSVCR120.dll을 설치합니다.

파일 이름에서 120 = 12.0 = Visual Studio 2013입니다.

DLL의 대상 플랫폼에 적합한 Visual Studio 버전 (10.0 = VS 10, 11 = VS 2012, 12.0 = VS 2013 ...)이 올바른 아키텍처 (x64 또는 x86)인지 확인하고주의해야합니다. 디버그 빌드. DLL의 디버그 빌드는 재배포 가능 패키지가 아닌 Visual Studio와 함께 설치되는 라이브러리의 디버그 버전 인 MSVCR120d.dll에 의존합니다.


dll의 전체 경로를 입력하십시오. 작동하지 않으면 dll을 system32 폴더에 복사 해보십시오.


DLL은 bin 폴더에 있어야합니다.

Visual Studio에서 dll을 내 프로젝트에 추가합니다 (참조에는 없지만 "기존 파일 추가"). 그런 다음 "Copy to Output Directory"속성을 "Copy if newer"로 설정합니다.


이것은 'kludge' 이지만 적어도 온전한 테스트에 사용할 수 있습니다. 코드에서 DLL 경로를 하드 코딩 해보십시오.

[DllImport(@"C:\\mycompany\\MyDLL.dll")]

라고 한; 제 경우에는 dumpbin /DEPENDENTS@ anthony-hayward가 제안한대로 실행 하고 거기에 나열된 32 비트 버전의 DLL을 제 작업 디렉토리에 복사 하면이 문제가 해결되었습니다.

로드 할 수없는 "내"dll이 아니기 때문에 메시지는 약간 오해의 소지가 있습니다.


자체 dll의 모든 종속성이 dll 근처 또는 System32.


당신의 시간을 낭비 할 수있는 아주 재미있는 일이 하나 있습니다.

콘솔 응용 프로그램 프로젝트 ConsoleApplication1와 클래스 라이브러리 프로젝트를 만들었습니다 ClassLibrary1.

p / invoke를 만드는 모든 코드는 ClassLibrary1.dll. 따라서 Visual Studio에서 애플리케이션을 디버깅하기 전에 CLR에서 런타임에로드 할 수 있도록 C ++ 관리되지 않는 어셈블리 ( myUnmanagedFunctions.dll)를 프로젝트 \bin\debug\디렉터리에 복사 ClassLibrary1했습니다.

나는 계속

DLL을로드 할 수 없습니다.

몇 시간 동안 오류. 나중에로드 될 모든 관리되지 않는 어셈블리를 일반적으로 win 폼, 콘솔 또는 웹 응용 프로그램 인 \bin\debug시작 프로젝트 디렉터리에 복사해야한다는 것을 깨달았 습니다 ConsoleApplication1.

따라서 Current Directory수락 된 답변에서 실제로 Current Directory응용 프로그램 프로세스가 시작되는 주 실행 파일을 의미 합니다. 명백한 것처럼 보이지만 때로는 그렇지 않을 수도 있습니다.

교훈 -항상 관리되지 않는 dll을 시작 실행 파일과 동일한 디렉토리에 두어 찾을 수 있는지 확인하십시오.


퓨전 로깅을 켜고 이를 수행하는 방법에 대한 많은 조언을 보려면 이 질문참조하십시오 . 혼합 모드 앱 로딩 문제를 디버깅하는 것은 왕실의 고통이 될 수 있습니다. 융합 로깅은 큰 도움이 될 수 있습니다.


빌드 플랫폼 대상을 x86 또는 x64로 설정하여 32 비트 플랫폼 용으로 컴파일 될 수있는 DLL과 호환되도록하십시오.


DLL과 .NET 프로젝트가 동일한 솔루션에 있고 매번 둘 다 컴파일하고 실행하려면 .NET 프로젝트, 빌드 이벤트의 속성을 마우스 오른쪽 단추로 클릭 한 다음 빌드 후 이벤트에 다음과 같은 항목을 추가 할 수 있습니다. 명령 줄 :

copy $(SolutionDir)Debug\MyOwn.dll .

기본적으로 DOS 라인이며 DLL이 빌드되는 위치에 따라 조정할 수 있습니다.


I had the same problem when I deployed my application to test PC. The problem was development PC had msvcp110d.dll and msvcr110d.dll but not the test PC.

I added "Visual Studio C++ 11.0 DebugCRT (x86)" merge module in InstalledSheild and it worked. Hope this will be helpful for someone else.


In my case one unmanaged dll was depending on another which was missing. In that case the error will point to the existing dll instead of the missing one which can be really confusing.

That is exactly what had happen in my case. Hope this helps someone else.


Setup: 32-bit Windows 7

Context: Installed a PCI-GPIB driver that I was unable to communicate through due to the aforementioned issue.

Short Answer: Reinstall the driver.

Long Answer: I also used Dependency Walker, which identified several missing dependency modules. Immediately, I thought that it must have been a botched driver installation. I didn't want to check and restore each missing file.

The fact that I was unable to find the uninstaller under Programs and Features of the Control Panel is another indicator of bad installation. I had to manually delete a couple of *.dll in \system32 and registry keys to allow for driver re-installation.

Issue fixed.

The unexpected part was that not all dependency modules were resolved. Nevertheless, the *.dll of interest can now be referenced.


I have come across the same problem, In my case I had two 32 bit pcs. One with .NET4.5 installed and other one was fresh PC.

my 32-bit cpp dll(Release mode build) was working fine with .NET installed PC but Not with fresh PC where I got the below error

Unable to load DLL 'PrinterSettings.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

finally,

I just built my project in Debug mode configuration and this time my cpp dll was working fine.


I think your unmanaged library needs a manifest.
Here is how to add it to your binary. and here is why.

In summary, several Redistributable library versions can be installed in your box but only one of them should satisfy your App, and it might not be the default, so you need to tell the system the version your library needs, that's why the manifest.


Also faced the same problem when using unmanaged c/c++ dll file in c# environment.

1.Checked the compatibility of dll with 32bit or 64bit CPU.

2.Checked the correct paths of DLL .bin folder, system32/sysWOW64 , or given path.

3.Checked if PDB(Programme Database) files are missing.This video gives you ans best undestand about pdb files.

When running 32-bit C/C++ binary code in 64bit system, could arise this because of platform incompatibility. You can change it from Build>Configuration manager.

참고URL : https://stackoverflow.com/questions/9003072/unable-to-load-dll-module-could-not-be-found-hresult-0x8007007e

반응형