/// <summary>
        /// Gets the Location of devenv.exe based on the RegistryRoot for the current package type
        /// </summary>
        private string getVSInstallDir(RegistrationContext context)
        {
            DefaultRegistryRootAttribute regRootAttr = (DefaultRegistryRootAttribute)TypeDescriptor.GetAttributes(context.ComponentType)[typeof(DefaultRegistryRootAttribute)];

            if (regRootAttr == null)
            {
                throw new NotSupportedException("could not find DefaultRegitryRootAttribute on " + context.ComponentType.ToString());
            }

            Win32.RegistryKey key = Win32.Registry.LocalMachine.OpenSubKey(regRootAttr.Root);
            //We are using HKCU in the case that the HKLM Experimental hive doesn't exist
            if (key == null || key.GetValue("InstallDir") == null)
            {
                key = Win32.Registry.CurrentUser.OpenSubKey(regRootAttr.Root + @"\Configuration");
            }
            string vsInstallDir = (string)key.GetValue("InstallDir");

            key.Close();
            return(vsInstallDir);
        }
Ejemplo n.º 2
0
        public static void InitSLApi()
        {
            // check if already initialized
            if (true == m_bSLApiInit)
            {
                return;
            }

            // we must check if debug pack is installed

            Win32.RegistryKey netFrameworkKey = null;
            IntPtr            procAddr        = IntPtr.Zero;

            try
            {
                netFrameworkKey = Win32.Registry.LocalMachine.OpenSubKey(
                    m_strNetFramework,
                    false);

                if (null == netFrameworkKey)
                {
                    throw new System.Exception("Unable to open the .NET Registry key: HKLM\\" + m_strNetFramework);
                }

                m_strDbgPackShimPath = (string)netFrameworkKey.GetValue(
                    m_strValDbgPackShimPath,
                    null,
                    RegistryValueOptions.DoNotExpandEnvironmentNames);

                if (null == m_strDbgPackShimPath)
                {
                    throw new System.Exception("Unable to open up the DbgPackShimPath registry key: HKLM\\" + m_strNetFramework + "\\" + m_strDbgPackShimPath);
                }

                // now initializing all the func ptrs
                m_hndModuleMscoree = LoadLib(m_strDbgPackShimPath);

                procAddr = GetProcAddr(m_hndModuleMscoree, "CreateDebuggingInterfaceFromVersion");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!CreateDebuggingInterfaceFromVersion");
                }
                else
                {
                    m_CreateDebuggingInterfaceFromVersion = (delgCreateDebuggingInterfaceFromVersion)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCreateDebuggingInterfaceFromVersion));
                }

                try
                {
                    procAddr = GetProcAddr(m_hndModuleMscoree, "CreateDebuggingInterfaceFromVersionEx");
                }
                catch (Win32Exception)
                {
                    procAddr = IntPtr.Zero;
                }
                if (IntPtr.Zero == procAddr)
                {
                    m_CreateDebuggingInterfaceFromVersionEx = null;
                    Console.WriteLine("This Silverlight/CoreCLR version doesn't have CDIFVex");
                }
                else
                {
                    m_CreateDebuggingInterfaceFromVersionEx = (delgCreateDebuggingInterfaceFromVersionEx)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCreateDebuggingInterfaceFromVersionEx));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "CreateVersionStringFromModule");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!CreateVersionStringFromModule");
                }
                else
                {
                    m_CreateVersionStringFromModule = (delgCreateVersionStringFromModule)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCreateVersionStringFromModule));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "EnumerateCLRs");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!EnumerateCLRs");
                }
                else
                {
                    m_EnumerateCLRs = (delgEnumerateCLRs)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgEnumerateCLRs));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "CloseCLREnumeration");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!CloseCLREnumeration");
                }
                else
                {
                    m_CloseCLREnumeration = (delgCloseCLREnumeration)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgCloseCLREnumeration));
                }

                procAddr = GetProcAddr(m_hndModuleMscoree, "GetStartupNotificationEvent");
                if (IntPtr.Zero == procAddr)
                {
                    throw new Exception("Failed to get address of dbgshim!GetStartupNotificationEvent");
                }
                else
                {
                    m_GetStartupNotificationEvent = (delgGetStartupNotificationEvent)Marshal.GetDelegateForFunctionPointer(
                        procAddr,
                        typeof(delgGetStartupNotificationEvent));
                }

                // We are done initializing
                m_bSLApiInit = true;
            }


            finally
            {
                if (null != netFrameworkKey)
                {
                    netFrameworkKey.Close();
                }

                // we will keep the cached handle to loaded mscoree.dll
                // around for a while..........
            }
        }