public Lib1Wrapper(string filename) { _dllhandle = NativeLibrary.LoadLibrary(filename); if (_dllhandle == IntPtr.Zero) { return; } var get_function_handle = NativeLibrary.GetProcAddress(_dllhandle, "GetString"); if (get_function_handle != IntPtr.Zero) { _getstring = (GetVersionDelegate)Marshal.GetDelegateForFunctionPointer(get_function_handle, typeof(GetVersionDelegate)); } }
public NXTProtocol(object s, NXTStreamType stype) { stream = s; streamType = stype; cmdThread = new Thread(CommandWorker); lsGetStatusDelegate = null; lsReadDelegate = null; ultrasonicDelegate = null; batteryLevelDelegate = null; getVersionDelegate = null; getOutputDelegate = null; getInputDelegate = null; messageReadDelegate = null; keepAliveDelegate = null; }
private void DelegateGetPlatformMessage() { // Get handle to method in DLL var get_version_handle = NativeLibrary.GetProcAddress(_dllhandle, "GetPlatformMessage"); // If successful, load function pointer if (get_version_handle != IntPtr.Zero) { _getversion = (GetVersionDelegate)Marshal.GetDelegateForFunctionPointer( get_version_handle, typeof(GetVersionDelegate)); } else { int win32error = Marshal.GetLastWin32Error(); Logger.Info($"Unable to get handle on GetProcAddress for GetPlatformMessage. Win32 error {win32error}"); } }
/// <summary> /// Initializes a new instance of the <see cref="WafNative"/> class. /// </summary> /// <param name="handle">Can't be a null pointer. Waf library must be loaded by now</param> internal WafNative(IntPtr handle) { _initField = GetDelegateForNativeFunction <InitDelegate>(handle, "ddwaf_init"); _destroyField = GetDelegateForNativeFunction <DestroyDelegate>(handle, "ddwaf_destroy"); _initContextField = GetDelegateForNativeFunction <InitContextDelegate>(handle, "ddwaf_context_init"); _runField = GetDelegateForNativeFunction <RunDelegate>(handle, "ddwaf_run"); _contextDestroyField = GetDelegateForNativeFunction <ContextDestroyDelegate>(handle, "ddwaf_context_destroy"); _resultFreeField = GetDelegateForNativeFunction <ResultFreeDelegate>(handle, "ddwaf_result_free"); _objectInvalidField = GetDelegateForNativeFunction <ObjectInvalidDelegate>(handle, "ddwaf_object_invalid"); _objectStringLengthFieldX64 = Environment.Is64BitProcess ? GetDelegateForNativeFunction <ObjectStringLengthDelegateX64>(handle, "ddwaf_object_stringl") : null; _objectStringLengthFieldX86 = Environment.Is64BitProcess ? null : GetDelegateForNativeFunction <ObjectStringLengthDelegateX86>(handle, "ddwaf_object_stringl"); _objectSignedField = GetDelegateForNativeFunction <ObjectSignedDelegate>(handle, "ddwaf_object_signed"); _objectUnsignField = GetDelegateForNativeFunction <ObjectUnsignedDelegate>(handle, "ddwaf_object_unsigned"); _objectArrayField = GetDelegateForNativeFunction <ObjectArrayDelegate>(handle, "ddwaf_object_array"); _objectMapField = GetDelegateForNativeFunction <ObjectMapDelegate>(handle, "ddwaf_object_map"); _objectArrayAddField = GetDelegateForNativeFunction <ObjectArrayAddDelegate>(handle, "ddwaf_object_array_add"); _objectMapAddFieldX64 = Environment.Is64BitProcess ? GetDelegateForNativeFunction <ObjectMapAddDelegateX64>(handle, "ddwaf_object_map_addl") : null; _objectMapAddFieldX86 = Environment.Is64BitProcess ? null : GetDelegateForNativeFunction <ObjectMapAddDelegateX86>(handle, "ddwaf_object_map_addl"); _objectFreeField = GetDelegateForNativeFunction <ObjectFreeDelegate>(handle, "ddwaf_object_free", out _objectFreeFuncPtrField); _getVersionField = GetDelegateForNativeFunction <GetVersionDelegate>(handle, "ddwaf_get_version"); // setup logging var setupLogging = GetDelegateForNativeFunction <SetupLoggingDelegate>(handle, "ddwaf_set_log_cb"); // convert to a delegate and attempt to pin it by assigning it to field setupLogCallbackField = LoggingCallback; // set the log level and setup the logger var level = GlobalSettings.Source.DebugEnabled ? DDWAF_LOG_LEVEL.DDWAF_DEBUG : DDWAF_LOG_LEVEL.DDWAF_INFO; setupLogging(Marshal.GetFunctionPointerForDelegate(setupLogCallbackField), level); }
internal string GetVersion() { this.ThrowIfDisposed(); if(this._GetVersionDelegate == null){ this._GetVersionDelegate = this.LoadMethod<GetVersionDelegate>("gflGetVersion"); } return Marshal.PtrToStringAnsi(this._GetVersionDelegate()); }