我需要手动处理实际的加载/卸载git2.dll
,而不是[DllImport("git2")]
在 C# 中使用。我似乎在创建一个IntPtr
用于引用存储在libgit2
.
这是我PluginManager
班级中的好东西,它们应该有助于促进手动加载、编组/委托(每当我修复这个扭结时)和卸载库。
public class PluginManager {
public const string LIB = "Assets\\Plugins\\git2.dll";
[DllImport( "kernel32.dll", CharSet = CharSet.Ansi )]
public static extern IntPtr LoadLibrary( [In, MarshalAs( UnmanagedType.LPStr )] string lib );
[DllImport( "kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true )]
public static extern IntPtr GetProcAddress( [In] IntPtr reference, [In, MarshalAs( UnmanagedType.LPStr )] string method );
[DllImport( "kernel32.dll" )]
public static extern bool FreeLibrary( [In] IntPtr reference );
}
这是我尝试使用它们的地方:
//# Working; always non-zero.
IntPtr reference = PluginManager.LoadLibrary( PluginManager.LIB );
//# Should be valid -- LibGit2Sharp.Core.NativeMethods.cs calls this method, too.
//# Always returns IntPtr.Zero.
IntPtr methodReference = PluginManager.GetProcAddress( reference, "git_repository_open" );
库是否没有暴露于这种类型的加载?我尝试了本LibGit2Sharp
机挂钩中存在的各种方法,但它们总是返回零。