예제 #1
0
        static Delegate GetProcDelegate <TDelegate>(SafeFreeLibrary lib, string procName)
        {
            IntPtr funcPtr = NativeMethods.GetProcAddress(lib, procName);

            if (funcPtr == IntPtr.Zero)
            {
                throw new Win32Exception(string.Format("Function '{0}' not found.", procName));
            }

            return(Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(TDelegate)));
        }
예제 #2
0
        static void EnsureInitialized()
        {
            if (initialized)
            {
                return;
            }

            lock (syncRoot)
            {
                if (initialized)
                {
                    return;
                }

                wasAPILib = NativeMethods.LoadLibraryEx(libName, IntPtr.Zero, NativeMethods.LOAD_WITH_ALTERED_SEARCH_PATH);
                webhostRegisterProtocol                 = (WAPI.WebhostRegisterProtocol)GetProcDelegate <WAPI.WebhostRegisterProtocol>(wasAPILib, "WebhostRegisterProtocol");
                webhostUnregisterProtocol               = (WAPI.WebhostUnregisterProtocol)GetProcDelegate <WAPI.WebhostUnregisterProtocol>(wasAPILib, "WebhostUnregisterProtocol");
                webhostOpenListenerChannelInstance      = (WAPI.WebhostOpenListenerChannelInstance)GetProcDelegate <WAPI.WebhostOpenListenerChannelInstance>(wasAPILib, "WebhostOpenListenerChannelInstance");
                webhostCloseAllListenerChannelInstances = (WAPI.WebhostCloseAllListenerChannelInstances)GetProcDelegate <WAPI.WebhostCloseAllListenerChannelInstances>(wasAPILib, "WebhostCloseAllListenerChannelInstances");
            }
        }
예제 #3
0
 public static extern IntPtr GetProcAddress(
     [In] SafeFreeLibrary hModule,
     [In] string lpProcName);