public static SafeWaitChainHandle OpenThreadWaitChainSession()
        {
            // Get the COM APIs into WCT. I have no idea why WCT just doesn't do this itself.
            if (oleModule == null)
            {
                oleModule = LoadLibraryW("OLE32.DLL");
                IntPtr coGetCallState       = GetProcAddress(oleModule, "CoGetCallState");
                IntPtr coGetActivationState = GetProcAddress(oleModule, "CoGetActivationState");
                // Register these functions with WCT.
                RegisterWaitChainCOMCallback(coGetCallState, coGetActivationState);
            }

            SafeWaitChainHandle wctHandle = RealOpenThreadWaitChainSession(0, IntPtr.Zero);

            if (wctHandle.IsInvalid == true)
            {
                throw new InvalidOperationException("Unable to open the Wait Thread Chain.");
            }
            return(wctHandle);
        }
 internal static extern IntPtr GetProcAddress(SafeModuleHandle hModule, string lpProcName);
        public static SafeWaitChainHandle OpenThreadWaitChainSession()
        {
            // Get the COM APIs into WCT. I have no idea why WCT just doesn't do this itself.
            if (oleModule == null)
            {
                oleModule = LoadLibraryW("OLE32.DLL");
                IntPtr coGetCallState = GetProcAddress(oleModule, "CoGetCallState");
                IntPtr coGetActivationState = GetProcAddress(oleModule, "CoGetActivationState");
                // Register these functions with WCT.
                RegisterWaitChainCOMCallback(coGetCallState, coGetActivationState);
            }

            SafeWaitChainHandle wctHandle = RealOpenThreadWaitChainSession(0, IntPtr.Zero);
            if (wctHandle.IsInvalid == true)
            {
                throw new InvalidOperationException("Unable to open the Wait Thread Chain.");
            }
            return (wctHandle);
        }
 internal static extern IntPtr GetProcAddress(SafeModuleHandle hModule, string lpProcName);