static NativeMethods() { var user32 = new UnmanagedLibrary( "user32" ); _pGetGestureInfoPtr = user32.GetUnmanagedFunction<GetGestureInfoPtr>( "GetGestureInfo" ); _pCloseGestureInfoHandle = user32.GetUnmanagedFunction<CloseGestureInfoHandlePtr>( "CloseGestureInfoHandle" ); _pSetGestureConfig = user32.GetUnmanagedFunction<SetGestureConfigPtr>( "SetGestureConfig" ); }
static LibZmq() { NativeLib = new UnmanagedLibrary(LibraryName); AssignCommonDelegates(); AssignCurrentVersion(out MajorVersion, out MinorVersion, out PatchVersion); if (MajorVersion >= 3) { zmq_getmsgopt = NativeLib.GetUnmanagedFunction<ZmqGetMsgOptProc>("zmq_getmsgopt"); zmq_recvmsg = NativeLib.GetUnmanagedFunction<ZmqRecvMsgProc>("zmq_recvmsg"); zmq_sendmsg = NativeLib.GetUnmanagedFunction<ZmqSendMsgProc>("zmq_sendmsg"); zmq_msg_init_data = NativeLib.GetUnmanagedFunction<ZmqMsgInitDataProc>("zmq_msg_init_data"); zmq_msg_move = NativeLib.GetUnmanagedFunction<ZmqMsgMoveProc>("zmq_msg_move"); PollTimeoutRatio = 1; } else if (MajorVersion == 2) { zmq_recvmsg = NativeLib.GetUnmanagedFunction<ZmqRecvMsgProc>("zmq_recv"); zmq_sendmsg = NativeLib.GetUnmanagedFunction<ZmqSendMsgProc>("zmq_send"); PollTimeoutRatio = 1000; } }
private static void LoadEntryPointsImpl(UnmanagedLibrary library, object functions) { var publicMembers = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance; foreach (var property in functions.GetType().GetProperties(publicMembers)) { var name = property.Name; // All entry point names have lower case, except for "Windows_run" switch (name) { case "Windows_run": break; default: name = char.ToLower(name[0], CultureInfo.InvariantCulture) + name.Substring(1); break; } // Event setters have a "FP" suffix if (name.StartsWith("set") && name != "setTextContents") { name += "FP"; } try { var function = library.GetUnmanagedFunction(name, property.PropertyType); if (function == null) { throw new ApplicationException(string.Format("Function {0} not found in AccessBridge", name)); } property.SetValue(functions, function, null); } catch (Exception e) { throw new ArgumentException(string.Format("Error loading function {0} from access bridge library", name), e); } } }
public PythonAPI(PythonVersion pyVer) { string dllName = pyVer.ToString().ToLower(); _pythonLibrary = new UnmanagedLibrary(dllName); Py_Initialize = _pythonLibrary.GetUnmanagedFunction<Action>("Py_Initialize"); Py_IsInitialized = _pythonLibrary.GetUnmanagedFunction<FuncInt>("Py_IsInitialized"); Py_Finalize = _pythonLibrary.GetUnmanagedFunction<Action>("Py_Finalize"); PyEval_InitThreads = _pythonLibrary.GetUnmanagedFunction<Action>("PyEval_InitThreads"); PyGILState_Ensure = _pythonLibrary.GetUnmanagedFunction<FuncIntPtr>("PyGILState_Ensure"); PyGILState_Release = _pythonLibrary.GetUnmanagedFunction<ActionIntPtr>("PyGILState_Release"); PyThreadState_Get = _pythonLibrary.GetUnmanagedFunction<FuncIntPtr>("PyThreadState_Get"); PyRun_String = _pythonLibrary.GetUnmanagedFunction<FuncStringIntIntPtrIntPtrIntPtr>("PyRun_String"); PyErr_Print = _pythonLibrary.GetUnmanagedFunction<Action>("PyErr_Print"); PyErr_Occurred = _pythonLibrary.GetUnmanagedFunction<FuncIntPtr>("PyErr_Occurred"); PyErr_Clear = _pythonLibrary.GetUnmanagedFunction<Action>("PyErr_Clear"); PyErr_Fetch = _pythonLibrary.GetUnmanagedFunction<ActionRIntPtrRIntPtrRIntPtr>("PyErr_Fetch"); PyImport_AddModule = _pythonLibrary.GetUnmanagedFunction<FuncStringIntPtr>("PyImport_AddModule"); PyModule_GetDict = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyModule_GetDict"); Py_IncRef = _pythonLibrary.GetUnmanagedFunction<ActionIntPtr>("Py_IncRef"); Py_DecRef = _pythonLibrary.GetUnmanagedFunction<ActionIntPtr>("Py_DecRef"); PyObject_HasAttrString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrStringInt>("PyObject_HasAttrString"); PyObject_GetAttrString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrStringIntPtr>("PyObject_GetAttrString"); PyObject_SetAttrString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrStringIntPtrInt>("PyObject_SetAttrString"); PyObject_Str = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyObject_Str"); PyObject_Compare = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtrInt>("PyObject_Compare"); PyCallable_Check = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrInt>("PyCallable_Check"); PyObject_CallObject = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtrIntPtr>("PyObject_CallObject"); PyObject_Length = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrInt>("PyObject_Length"); PyObject_Dir = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyObject_Dir"); PyObject_Type = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyObject_Type"); PyObject_IsInstance = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtrInt>("PyObject_IsInstance"); PyString_FromString = _pythonLibrary.GetUnmanagedFunction<FuncStringIntPtr>("PyString_FromString"); PyString_AsString = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntPtr>("PyString_AsString"); PySys_GetObject = _pythonLibrary.GetUnmanagedFunction<FuncStringIntPtr>("PySys_GetObject"); PyInt_AsLong = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrInt>("PyInt_AsLong"); PyLong_AsLongLong = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrLong>("PyLong_AsLongLong"); PyFloat_AsDouble = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrDouble>("PyFloat_AsDouble"); PyTuple_New = _pythonLibrary.GetUnmanagedFunction<FuncIntIntPtr>("PyTuple_New"); PyTuple_SetItem = _pythonLibrary.GetUnmanagedFunction<FuncIntPtrIntIntPtrInt>("PyTuple_SetItem"); PyType_Type = _pythonLibrary.GetGlobalVar("PyType_Type"); PyBaseObject_Type = _pythonLibrary.GetGlobalVar("PyBaseObject_Type"); PyString_Type = _pythonLibrary.GetGlobalVar("PyString_Type"); PyUnicode_Type = _pythonLibrary.GetGlobalVar("PyUnicode_Type"); PyInt_Type = _pythonLibrary.GetGlobalVar("PyInt_Type"); PyLong_Type = _pythonLibrary.GetGlobalVar("PyLong_Type"); PyBool_Type = _pythonLibrary.GetGlobalVar("PyBool_Type"); PyFloat_Type = _pythonLibrary.GetGlobalVar("PyFloat_Type"); }
static LibZmq() { NativeLib = new UnmanagedLibrary(LibraryName); AssignCommonDelegates(); AssignCurrentVersion(out MajorVersion, out MinorVersion, out PatchVersion); if (MajorVersion >= 3) { zmq_msg_get = NativeLib.GetUnmanagedFunction<ZmqMsgGetProc>("zmq_msg_get"); zmq_msg_init_data = NativeLib.GetUnmanagedFunction<ZmqMsgInitDataProc>("zmq_msg_init_data"); zmq_msg_move = NativeLib.GetUnmanagedFunction<ZmqMsgMoveProc>("zmq_msg_move"); var zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_msg_recv"); zmq_msg_recv = zmq_msg_recv_impl; //used to receive raw buffer (rjoshi) var zmq_buffer_recv_impl = NativeLib.GetUnmanagedFunction<ZmqBufferRecvProc>("zmq_recv"); zmq_buffer_recv = zmq_buffer_recv_impl; var zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_msg_send"); zmq_msg_send = zmq_msg_send_impl; //used to send raw buffer (rjoshi) var zmq_buffer_send_impl = NativeLib.GetUnmanagedFunction<ZmqBufferSendProc>("zmq_send"); zmq_buffer_send = zmq_buffer_send_impl; zmq_ctx_new = NativeLib.GetUnmanagedFunction<ZmqCtxNewProc>("zmq_ctx_new"); zmq_ctx_destroy = NativeLib.GetUnmanagedFunction<ZmqCtxDestroyProc>("zmq_ctx_destroy"); zmq_ctx_get = NativeLib.GetUnmanagedFunction<ZmqCtxGetProc>("zmq_ctx_get"); zmq_ctx_set = NativeLib.GetUnmanagedFunction<ZmqCtxSetProc>("zmq_ctx_set"); zmq_ctx_set_monitor = NativeLib.GetUnmanagedFunction<ZmqCtxSetMonitorProc>("zmq_ctx_set_monitor"); zmq_unbind = NativeLib.GetUnmanagedFunction<ZmqBindProc>("zmq_unbind"); zmq_disconnect = NativeLib.GetUnmanagedFunction<ZmqConnectProc>("zmq_disconnect"); PollTimeoutRatio = 1; ZmqMsgTSize = Zmq3MsgTSize; } else if (MajorVersion == 2) { var zmq_msg_recv_impl = NativeLib.GetUnmanagedFunction<ZmqMsgRecvProc>("zmq_recv"); var zmq_msg_send_impl = NativeLib.GetUnmanagedFunction<ZmqMsgSendProc>("zmq_send"); zmq_msg_send = (msg, sck, flags) => zmq_msg_send_impl(sck, msg, flags); zmq_msg_recv = (msg, sck, flags) => zmq_msg_recv_impl(sck, msg, flags); var zmq_init = NativeLib.GetUnmanagedFunction<ZmqInitProc>("zmq_init"); zmq_ctx_new = () => zmq_init(1); zmq_ctx_destroy = NativeLib.GetUnmanagedFunction<ZmqCtxDestroyProc>("zmq_term"); PollTimeoutRatio = 1000; ZmqMsgTSize = Zmq2MsgTSize; } }