C#(统一)跨平台呼叫C++;运行时的DLL函数

C#(统一)跨平台呼叫C++;运行时的DLL函数,c#,c++,dll,C#,C++,Dll,基于这里的一些其他问题,我能够在运行时调用本机(C++)DLL函数,并首先使用此代码加载DLL [DllImport("kernel32.dll")] public static extern IntPtr LoadLibrary( string dllToLoad ); [DllImport("kernel32.dll")] public stati

基于这里的一些其他问题,我能够在运行时调用本机(C++)DLL函数,并首先使用此代码加载DLL

[DllImport("kernel32.dll")]
        public static extern IntPtr LoadLibrary(
            string dllToLoad
        );
        
        [DllImport("kernel32.dll")]
        public static extern IntPtr GetProcAddress(
            IntPtr hMod,
            string procShaym
        );
        
        [DllImport("kernel32.dll")]
        public static extern bool FreeLibrary(
            IntPtr hMod
        );
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private 
        delegate 
        int 
        MultiplyByTen();
        
        public static int Wellz(
            string pth,
            string fname
        ) { 
            var dll = LoadLibrary(
                    pth
                );
            if(dll == IntPtr.Zero) {
                return -1;
            }
            
            var address = GetProcAddress(
                    dll, fname                  
                );
                
            if(dll == IntPtr.Zero) {
                return -2;
            }
            
            var fnc = Marshal
                .GetDelegateForFunctionPointer(
                    address,
                    typeof(MultiplyByTen)
                ) as MultiplyByTen;
            var raz
            = fnc();
            return raz;
}
在windows x64中运行良好(至少)

正如您可能已经注意到的,虽然此方法严重依赖于kernel32.dll调用,但为了读取特定的dll等

对于不需要依赖于kernel32.dll的跨平台代码,有没有办法做到这一点