Ejemplo n.º 1
0
        static Delegate GetProcDelegate <TDelegate>(WebHostUnsafeNativeMethods.SafeFreeLibrary library, string procName)
        {
#pragma warning suppress 56523 // [....], the Win32Exception ctor calls Marshal.GetLastWin32Error
            IntPtr funcPtr = WebHostUnsafeNativeMethods.GetProcAddress(library, procName);
            if (funcPtr == IntPtr.Zero)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(SR.GetString(SR.WebHostProcNotFound,
                                                                                                          procName, SMSvcHost.ListenerAdapterNativeLibrary)));
            }

            return(Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(TDelegate)));
        }
Ejemplo n.º 2
0
        static ListenerAdapterBase()
        {
#pragma warning suppress 56523 // [....], the Win32Exception ctor calls Marshal.GetLastWin32Error
            webHostIpm = WebHostUnsafeNativeMethods.LoadLibraryEx(SMSvcHost.ListenerAdapterNativeLibrary, IntPtr.Zero, WebHostUnsafeNativeMethods.LOAD_WITH_ALTERED_SEARCH_PATH);
            if (webHostIpm.IsInvalid)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception());
            }

            webhostGetVersion                       = (WebHostUnsafeNativeMethods.WebhostGetVersion)GetProcDelegate <WebHostUnsafeNativeMethods.WebhostGetVersion>(webHostIpm, "WebhostGetVersion");
            webhostRegisterProtocol                 = (WebHostUnsafeNativeMethods.WebhostRegisterProtocol)GetProcDelegate <WebHostUnsafeNativeMethods.WebhostRegisterProtocol>(webHostIpm, "WebhostRegisterProtocol");
            webhostUnregisterProtocol               = (WebHostUnsafeNativeMethods.WebhostUnregisterProtocol)GetProcDelegate <WebHostUnsafeNativeMethods.WebhostUnregisterProtocol>(webHostIpm, "WebhostUnregisterProtocol");
            webhostOpenListenerChannelInstance      = (WebHostUnsafeNativeMethods.WebhostOpenListenerChannelInstance)GetProcDelegate <WebHostUnsafeNativeMethods.WebhostOpenListenerChannelInstance>(webHostIpm, "WebhostOpenListenerChannelInstance");
            webhostCloseAllListenerChannelInstances = (WebHostUnsafeNativeMethods.WebhostCloseAllListenerChannelInstances)GetProcDelegate <WebHostUnsafeNativeMethods.WebhostCloseAllListenerChannelInstances>(webHostIpm,
                                                                                                                                                                                                               "WebhostCloseAllListenerChannelInstances");
        }