문제

Scintilla.net에서 사용하는 MANIDAD DLL (Scintilla Code Editor의 Scilexer.dll)이 있습니다. 코드 플렉스) 이는 Scintilla.net 구성 요소를 관리하는 관리 응용 프로그램에서로드됩니다. Windows Managed Application은 32 및 64 비트 환경에서 문제없이 실행되지만 64 또는 32 Scilexer.dll을 사용하는 다른 설치를 만들어야합니다.

.NET Framework의 DLL 로더가 .config 옵션 또는 "경로 이름 매직"에 따라 32 또는 64 비트 형식의 DLL을 32 또는 64 비트 형식으로로드 할 수 있도록 32 및 64 비트 형식으로 DLL을 배포하는 방법이 있습니까?

도움이 되었습니까?

해결책

p/invoke는 loadLibrary를 사용하여 DLL을로드하고, 이미 주어진 이름이 장착 된 라이브러리가있는 경우 LoadLibrary를 반환합니다. 따라서 두 버전의 DLL을 동일한 이름으로 제공 할 수 있지만 다른 디렉토리에 넣으면 Scilexer.dll의 기능을 첫 번째 호출하기 직전에 외부 선언을 복제 할 필요없이 다음과 같은 작업을 수행 할 수 있습니다.

    string platform = IntPtr.Size == 4 ? "x86" : "x64";
    string dll = installDir + @"\lib-" + platform + @"\scilexer.dll";
    if (LoadLibrary(dll) == IntPtr.Zero)
        throw new IOException("Unable to load " + dll + ".");

다른 팁

불행히도, 나는이 특정 DLL에 대해 아무것도 모른다. 그러나 P/호출을 직접 수행하고 약간의 복제에 대처할 수 있으면 각 플랫폼마다 하나의 프록시를 만들 수 있습니다.

예를 들어, 32 또는 64 비트 DLL로 구현 해야하는 다음 인터페이스가 있다고 가정합니다.

public interface ICodec {
    int Decode(IntPtr input, IntPtr output, long inputLength);
}

프록시를 만듭니다.

public class CodecX86 : ICodec {
    private const string dllFileName = @"Codec.x86.dll";

    [DllImport(dllFileName)]
    static extern int decode(IntPtr input, IntPtr output, long inputLength);

    public int Decode(IntPtr input, IntPtr output, long inputLength) {
        return decode(input, output, inputLength);
    }
}

그리고

public class CodecX64 : ICodec {
    private const string dllFileName = @"Codec.x64.dll";

    [DllImport(dllFileName)]
    static extern int decode(IntPtr input, IntPtr output, long inputLength);

    public int Decode(IntPtr input, IntPtr output, long inputLength) {
        return decode(input, output, inputLength);
    }
}

그리고 마지막으로 당신을 위해 올바른 것을 선택하는 공장을 만듭니다.

public class CodecFactory {
    ICodec instance = null;

    public ICodec GetCodec() {
        if (instance == null) {
            if (IntPtr.Size == 4) {
                instance = new CodecX86();
            } else if (IntPtr.Size == 8) {
                instance = new CodecX64();
            } else {
                throw new NotSupportedException("Unknown platform");
            }
        }
        return instance;
    }
}

처음으로 호출 될 때 DLL이 게으르게로드됨에 따라, 이것은 각 플랫폼이 기본 버전을로드 할 수 있음에도 불구하고 실제로 작동합니다. 보다 이 기사 더 자세한 설명을 위해.

내가 생각해 낸 최고는 다음과 같습니다.

  • 64 또는 32라는 두 개의 DLL로 내 응용 프로그램을 배포하십시오.
  • 기본 시작 코드에는 다음이 포함됩니다.
    
    File.Delete(Application.StartupPath + @"\scilexer.dll");
    {
      // Check for 64 bit and copy the proper scilexer dll
        if (IntPtr.Size == 4)
        {
          File.Copy(Application.StartupPath + @"\scilexer32.dll",
            Application.StartupPath + @"\scilexer.dll");
        }
        else
        {
          File.Copy(Application.StartupPath + @"\scilexer64.dll",
            Application.StartupPath + @"\scilexer.dll");
        }
    }

DLL을 System32에 넣을 수 있습니다. Syswow64의 32 비트 및 실제 시스템에서 64 비트. 32 비트 적용의 경우, Access System32가 Syswow64로 리디렉션됩니다.

레지스트리에서 항목을 만들 수 있습니다. 소프트웨어 키에는 32 비트 애플리케이션이 소프트웨어 키로 보는 WOW6432Node라는 서브 키가 있습니다.

여기에 무엇이 있습니다 PowerShell 설치 프로그램.

관리되지 않는 DLL은 관리되는 상대와 함께 GAC에 나란히 설치할 수 있습니다. 이 기사 그것이 어떻게 작동하는지 설명해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top