public NativeTestLib() { if (NativeLib == null) { // can we use a static constructor, or interplay with load time? var fname = PlatformUtility.CreateLibraryFileName("test_native_library"); var testLibPathEnv = "DynamicInteropTestLibPath"; if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(testLibPathEnv))) { string guess = GuessTestLibPath(); if (Directory.Exists(guess)) { Environment.SetEnvironmentVariable(testLibPathEnv, guess); } else { //testLibPathEnv = ""; string msg = "You need to set an environment variable e.g.: " + @"set DynamicInteropTestLibPath=C:\src\dynamic-interop-dll\x64\Debug"; throw new Exception(msg); } } string nativeLibFilename = PlatformUtility.FindFirstFullPath(fname, "test_delegate_library DLL", testLibPathEnv); NativeLib = new UnmanagedDll(nativeLibFilename); } }
private void CreateLib(string fname) { using (var dll = new UnmanagedDll(fname)) { // do nothing. } }
public static void Main(string[] args) { var nat = new UnmanagedDll(args[0]); Console.WriteLine("Looks good"); //LowLevelTest (args); }
public RclrUnmanagedDll(string dllName) { if (!File.Exists(dllName)) { throw new FileNotFoundException(dllName); } this.dll = new UnmanagedDll(dllName); this.ClrObjectToSexp = dll.GetFunction<ClrObjectToSexpDelegate>("clr_object_to_SEXP"); }
private void TestLoadKernel32() { using (var dll = new UnmanagedDll("kernel32.dll")) { var beep = dll.GetFunction <Beep>(); Assert.NotNull(beep); //beep(400, 1000); var areFileApisAnsi = dll.GetFunction <AreFileApisANSI>(); var b = areFileApisAnsi(); // does not throw. } }
private void TestLoadLibc() { // TODO: obviously need to generalize this. //nm -D --defined-only /lib/x86_64-linux-gnu/libc.so.6 | less using (var dll = new UnmanagedDll("/lib/x86_64-linux-gnu/libc.so.6")) { var m = dll.GetFunction <malloc>(); Assert.NotNull(m); } }
static void Main(string[] args) { // Environment.CurrentDirectory //"C:\\src\\github_jm\\dynamic-interop-dll\\examples\\ProgressUpdateApp" myNativeDll = new UnmanagedDll(@"..\x64\Debug\progress_update_native.dll"); Console.WriteLine("Register with the C++ native library the C# function to call back..."); CallbackHandlers.SetProgressUpdateCallback(); Console.WriteLine("About to call native task..."); LaunchLongLivedNativeTask(); Console.WriteLine("Native task finished and returned"); }
static void LowLevelTest(string[] args) { var nat = new UnmanagedDll ("libdl.so"); var open = nat.GetFunction<dlopen> ("dlopen"); var error = nat.GetFunction<dlerror> ("dlerror"); IntPtr handle = open (args [0], 0x01); if (IntPtr.Zero == handle) { Console.WriteLine ("failed!!"); var msg = error (); if (!string.IsNullOrEmpty (msg)) Console.WriteLine (msg); } else { Console.WriteLine ("Success!!"); } }
static void LowLevelTest(string[] args) { var nat = new UnmanagedDll("libdl.so"); var open = nat.GetFunction <dlopen> ("dlopen"); var error = nat.GetFunction <dlerror> ("dlerror"); IntPtr handle = open(args [0], 0x01); if (IntPtr.Zero == handle) { Console.WriteLine("failed!!"); var msg = error(); if (!string.IsNullOrEmpty(msg)) { Console.WriteLine(msg); } } else { Console.WriteLine("Success!!"); } }
public static void Main(string[] args) { var nat = new UnmanagedDll (args[0]); Console.WriteLine ("Looks good"); //LowLevelTest (args); }
unsafe public static void Initialize(string migemoPath = null, string migemoDictionaryPath = null) { try { if (IsEnable()) { Dispose(); } string migemoFileName; if (Environment.Is64BitProcess) { migemoFileName = "migemo.dll"; } else { migemoFileName = "migemo32.dll"; } string migemoRootDir; string dllPath; if (string.IsNullOrEmpty(migemoPath)) { migemoRootDir = System.IO.Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString(); dllPath = System.IO.Path.Combine(migemoRootDir, migemoFileName); } else { migemoRootDir = migemoPath; dllPath = System.IO.Path.Combine(migemoPath, migemoFileName); } if (!System.IO.File.Exists(dllPath)) { throw new DllNotFoundException("migemo.dll not found"); } migemoDll = new UnmanagedDll(dllPath); migemo_open = migemoDll.GetProcDelegate <MigemoOpen>("migemo_open"); migemo_close = migemoDll.GetProcDelegate <MigemoClose>("migemo_close"); migemo_query = migemoDll.GetProcDelegate <MigemoQuery>("migemo_query"); migemo_release = migemoDll.GetProcDelegate <MigemoRelease>("migemo_release"); migemo_set_operator = migemoDll.GetProcDelegate <MigemoSetOperator>("migemo_set_operator"); migemo_get_operator = migemoDll.GetProcDelegate <MigemoGetOperator>("migemo_get_operator"); migemo_load = migemoDll.GetProcDelegate <MigemoLoad>("migemo_load"); migemo_is_enable = migemoDll.GetProcDelegate <MigemoIsEnable>("migemo_is_enable"); migemo_setproc_int2char = migemoDll.GetProcDelegate <MigemoSetProcInt2Char>("migemo_setproc_int2char"); string dictpath = migemoDictionaryPath; if (string.IsNullOrEmpty(dictpath)) { dictpath = System.IO.Path.Combine(@migemoRootDir, "dict/migemo-dict"); if (!System.IO.File.Exists(dictpath)) { dictpath = System.IO.Path.Combine(@migemoRootDir, "dict/utf-8/migemo-dict"); } } MigemoObject = migemo_open(dictpath); MigemoStruct migemoStruct = new MigemoStruct(); migemoStruct = Marshal.PtrToStructure <MigemoStruct>(MigemoObject); if (!IsEnable()) { throw new DllNotFoundException("cannot read dictionary"); } OperatorNestIn = "(?:"; if (migemoStruct.charset == CharSet.Cp932) { int2char_delegate = ProcAnsiInt2Char; migemo_setproc_int2char(MigemoObject, int2char_delegate); } else if (migemoStruct.charset == CharSet.UTF8) { int2char_delegate = ProcUtf8Int2Char; migemo_setproc_int2char(MigemoObject, int2char_delegate); } AppDomain.CurrentDomain.ProcessExit += (o, e) => { Dispose(); }; } catch (Exception ex) { throw new Exception("cannot load migemo.dll or dictionary", ex); } }