加载x86或x64汇编 [英] Loading x86 or x64 assembly

查看:252
本文介绍了加载x86或x64汇编的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个版本System.Data.SQLite.DLL的 - 用于x86和x64平台。 x86版本保留在应用程序文件夹和x64版本appFolder \ x64文件夹中保存。 编译成值为anycpu中的应用。 我怎么能负载所需根据windows平台版本的SQLite?

I have two versions of System.Data.SQLite.DLL - for x86 and x64 platform. The x86 version keeps in application folder and x64 version keeps in appFolder\x64 folder. The application compiled as AnyCPU. How can i load needed version of SQLite according to windows platform?

推荐答案

如果您正在使用SQLite HTTP://system.data.sqlite .org等的System.Data.SQLite.DLL完全管理。有一个潜在的机DLL,SQLite.Interop.DLL,需要根据过程(32位或64位)来改变。

If you are using SQLite from http://system.data.sqlite.org, the System.Data.SQLite.DLL is completely managed. There is an underlying native DLL, SQLite.Interop.DLL, that needs to change depending on the process (32- or 64-bit).

我部署。\本地\ X64本机库的64位和\本地\ X86为32位。在运行时的P / Invoke SetDllDirectory会设置DLL加载目录指着的过程中,正确的路径。 <一href="http://msdn.microsoft.com/en-us/library/ms686203(v=vs.85).aspx">http://msdn.microsoft.com/en-us/library/ms686203(v=vs.85).aspx

I deploy the native libraries in ".\Native\X64" for 64-bit and ".\Native\X86" for 32-bit. At runtime P/Invoke SetDllDirectory to set the DLL load directory pointing at the correct path for the process. http://msdn.microsoft.com/en-us/library/ms686203(v=vs.85).aspx

(请注意,我不熟悉的遗产System.Data.SQLite.DLL版本从 HTTP架构://sqlite.phxsoftware。 COM

(Note that I'm not familiar with the architecture of the legacy System.Data.SQLite.DLL version from http://sqlite.phxsoftware.com)

private static class NativeMethods
{
    [DllImport("kernel32.dll", CallingConvention = CallingConvention.Cdecl)]
    internal static extern bool SetDllDirectory(string pathName);
}

... 

    // Underlying SQLite libraries are native. 
    // Manually set the DLL load path depending on the process.
    var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Native");
    if(IntPtr.Size == 8) // or: if(Environment.Is64BitProcess) // .NET 4.0
    {
        path = Path.Combine(path, "X64");
    }
    else
    {
        // X32
        path = Path.Combine(path, "X86");
    }
    NativeMethods.SetDllDirectory(path);

这篇关于加载x86或x64汇编的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆