Beispiel #1
0
        public IComInterop Plus1Me(int x)
        {
            var temp = new ComInterop();

            temp.Plus1(x);
            return(temp);
        }
Beispiel #2
0
        private void AddCoClassMembers(SortedList members)
        {
            int implCount = ComInterop.GetImplTypeCount(m_typeInfo.ComType);

            for (int index = 0; index < implCount; ++index)
            {
                IMPLTYPEFLAGS implTypeFlags;
                m_typeInfo.ComType.GetImplTypeFlags(index, out implTypeFlags);

                if ((implTypeFlags & IMPLTYPEFLAGS.IMPLTYPEFLAG_FDEFAULT) == IMPLTYPEFLAGS.IMPLTYPEFLAG_FDEFAULT)
                {
                    // This is a default interface - gets the corresponding ComTypeBrowserInfo object.

                    int href;
                    m_typeInfo.ComType.GetRefTypeOfImplType(index, out href);

                    ITypeInfo refTypeInfo;
                    m_typeInfo.ComType.GetRefTypeInfo(href, out refTypeInfo);
                    Debug.Assert(refTypeInfo != null, "refTypeInfo != null");

                    // Check if this interface is an event source.

                    bool isEventSource = ((implTypeFlags & IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE) == IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE);

                    // Add each member of the base interface to our members collection.

                    ComTypeBrowserInfo baseType = Manager.GetTypeInfo(refTypeInfo);

                    AddTypeMembersRecursive(baseType, members, isEventSource);
                }
            }
        }
Beispiel #3
0
        private SortedList GetBaseTypes()
        {
            Debug.Assert(m_typeInfo != null, "m_typeInfo != null");

            SortedList baseTypes = new SortedList();

            // Add the implemented types.

            int implCount = ComInterop.GetImplTypeCount(m_typeInfo.ComType);

            for (int index = 0; index < implCount; ++index)
            {
                int href;
                m_typeInfo.ComType.GetRefTypeOfImplType(index, out href);

                ITypeInfo refTypeInfo;
                m_typeInfo.ComType.GetRefTypeInfo(href, out refTypeInfo);
                Debug.Assert(refTypeInfo != null, "refTypeInfo != null");

                string name = Marshal.GetTypeInfoName(refTypeInfo);

                // Do not display IUnknown or IDispatch.

                if (!(name == "IUnknown" || name == "IDispatch"))
                {
                    baseTypes.Add(Manager.GetTypeInfo(refTypeInfo), null);
                }
                else
                {
                    Marshal.ReleaseComObject(refTypeInfo);
                }
            }

            return(baseTypes);
        }
Beispiel #4
0
        public static void CompileMofFile(string fileName, string serverAndNamespace, string user,
                                          string authority, string password)
        {
            const string method = "CompileMofFile";

            if (fileName == null)
            {
                throw new NullParameterException(typeof(WmiUtil), method, "fileName");
            }
            if (serverAndNamespace == null)
            {
                throw new NullParameterException(typeof(WmiUtil), method, "serverAndNamespace");
            }

            // The MofCompiler returns a completely useless error if it cannot open the file, so
            // instead of calling CompileFile() read the MOF file into a buffer and call CompileBuffer().

            int length;

            byte[] buffer;
            using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                length = (int)stream.Length;
                buffer = new byte[length];
                stream.Read(buffer, 0, length);
            }

            // Create a MofCompiler COM object.

            Win32.IMofCompiler mofCompiler = (Win32.IMofCompiler)ComInterop.CreateComInstance(
                new System.Guid(Constants.Win32.IIDs.IID_MofCompiler), typeof(Win32.IMofCompiler));
            Debug.Assert(mofCompiler != null, "mofCompiler != null");

            // Compile the MOF file.

            Win32.WBEM_COMPILE_STATUS_INFO status = new Win32.WBEM_COMPILE_STATUS_INFO();
            try
            {
                mofCompiler.CompileBuffer(length, buffer, serverAndNamespace, user, authority, password,
                                          Win32.WBEM_COMPILER_OPTIONS.None, Win32.WBEM_COMPILER_OPTIONS.None,
                                          Win32.WBEM_COMPILER_OPTIONS.None, ref status);
            }
            finally
            {
                Marshal.ReleaseComObject(mofCompiler);
            }

            // Check the status code and throw an exception if the compilation failed.

            if (status.lPhaseError != 0)
            {
                string facility;
                string message = GetWmiErrorMessage(status.hRes, out facility);

                throw new WmiMofFileCompileException(typeof(WmiUtil), method, fileName,
                                                     serverAndNamespace, status.lPhaseError, status.ObjectNum, status.FirstLine,
                                                     status.LastLine, status.hRes, facility, message);
            }
        }
Beispiel #5
0
        public virtual TypeLibraryBrowserInfo GetTypeLibraryInfo(string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            return(GetTypeLibraryInfo(filePath, ComInterop.LoadTypeLibrary(filePath)));
        }
Beispiel #6
0
        private static string GetWmiErrorMessage(int hResult, out string facility)
        {
            Win32.IWbemStatusCodeText statusCodeText = (Win32.IWbemStatusCodeText)ComInterop.CreateComInstance(
                new System.Guid(Constants.Win32.IIDs.IID_WbemClassObject), typeof(Win32.IWbemStatusCodeText));
            Debug.Assert(statusCodeText != null, "statusCodeText != null");

            try
            {
                facility = statusCodeText.GetFacilityCodeText(hResult, 0, 0);
                return(statusCodeText.GetErrorCodeText(hResult, 0, 0).TrimEnd(new char[] { '\r', '\n' }));
            }
            finally
            {
                Marshal.ReleaseComObject(statusCodeText);
            }
        }
Beispiel #7
0
 internal static void Initialize(ComInterop.IWinSock winSock)
 {
     WinSock.winSock = winSock;
     threadId = Thread.CurrentThread.ManagedThreadId;
 }
 internal TypeLibraryBrowserInfo(ITypeLib typeLibrary, ComBrowserManager manager)
     : this(ComInterop.GetTypeLibPath(typeLibrary), typeLibrary, manager)
 {
 }