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))); }
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"); } }
public static extern IntPtr GetProcAddress( [In] SafeFreeLibrary hModule, [In] string lpProcName);