4 using System.Globalization;
6 using System.Runtime.InteropServices;
8 namespace SiliconStudio.Core
12 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
13 [DllImport(
"kernel32", EntryPoint =
"LoadLibrary", SetLastError =
true, CharSet = CharSet.Unicode)]
14 static extern IntPtr LoadLibrary(
string lpFileName);
15 #elif SILICONSTUDIO_PLATFORM_WINDOWS_PHONE
16 [DllImport(
"PhoneAppModelHost", CharSet = CharSet.Unicode, SetLastError =
true)]
17 private static extern IntPtr LoadPackagedLibrary(
string libraryName, uint reserved);
18 #elif SILICONSTUDIO_PLATFORM_WINDOWS_STORE
19 [DllImport(
"kernel32", CharSet = CharSet.Unicode, SetLastError =
true)]
20 private static extern IntPtr LoadPackagedLibrary(
string libraryName, uint reserved);
26 #if SILICONSTUDIO_PLATFORM_IOS
27 public const string LibraryName =
"__Internal";
29 public const string LibraryName =
"libcore.dll";
35 public const CallingConvention CallConvention = CallingConvention.Cdecl;
46 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
47 var systemInfo =
new SYSTEM_INFO();
48 GetNativeSystemInfo(out systemInfo);
51 if (systemInfo.processorArchitecture == PROCESSOR_ARCHITECTURE.PROCESSOR_ARCHITECTURE_ARM)
54 cpu = IntPtr.Size == 8 ?
"x64" :
"x86";
55 var libraryFilename = Path.Combine(Path.GetDirectoryName(typeof(
NativeLibrary).Assembly.Location), cpu, libraryName);
56 var result = LoadLibrary(libraryFilename);
58 if (result == IntPtr.Zero)
59 throw new InvalidOperationException(
string.Format(
"Could not load native library {0} using CPU architecture {1}.", libraryName, cpu));
63 #if SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
64 private const string SYSINFO_FILE =
"API-MS-WIN-CORE-SYSINFO-L1-2-1.DLL";
66 private const string SYSINFO_FILE =
"kernel32.dll";
69 [DllImport(SYSINFO_FILE)]
70 static extern void GetNativeSystemInfo(out SYSTEM_INFO lpSystemInfo);
72 [StructLayout(LayoutKind.Sequential)]
75 public PROCESSOR_ARCHITECTURE processorArchitecture;
78 public IntPtr minimumApplicationAddress;
79 public IntPtr maximumApplicationAddress;
80 public IntPtr activeProcessorMask;
81 public uint numberOfProcessors;
82 public uint processorType;
83 public uint allocationGranularity;
84 public ushort processorLevel;
85 public ushort processorRevision;
88 enum PROCESSOR_ARCHITECTURE : ushort
90 PROCESSOR_ARCHITECTURE_AMD64 = 9,
91 PROCESSOR_ARCHITECTURE_ARM = 5,
92 PROCESSOR_ARCHITECTURE_IA64 = 6,
93 PROCESSOR_ARCHITECTURE_INTEL = 0,
94 PROCESSOR_ARCHITECTURE_UNKNOWN = 0xffff
static void PreloadLibrary(string libraryName)
Try to preload the library. This is useful when we want to have AnyCPU .NET and CPU-specific native c...