예제 #1
0
파일: Silverlight.cs 프로젝트: Orvid/Cosmos
        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..........
            }

        }
예제 #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..........
            }
        }