コード例 #1
0
    public static void Main()
    {
        Assembly               asm          = Assembly.LoadFrom("MyAssembly.dll");
        TypeLibConverter       converter    = new TypeLibConverter();
        ConversionEventHandler eventHandler = new ConversionEventHandler();

        UCOMICreateITypeLib typeLib = (UCOMICreateITypeLib)converter.ConvertAssemblyToTypeLib(asm, "MyTypeLib.dll", 0, eventHandler);

        typeLib.SaveAllChanges();
    }
        public void BuildLib(string targetFolder) {
            NativeMethods.LoadTypeLibEx(VBoxWrapper.COMInterface.VBoxComUtils.GetVirtualBoxComTypeLib(), NativeMethods.RegKind.RegKind_None, out _typeLibInMemory);
            if (_typeLibInMemory == null) {
                throw new DllNotFoundException("Could not load Virtualbox-Typelibrary.");
            }


            TypeLibConverter converter = new TypeLibConverter();
            ConversionEventHandler handler = new ConversionEventHandler();

            AssemblyBuilder asm = converter.ConvertTypeLibToAssembly(_typeLibInMemory, "Interop.VirtualBox.dll", TypeLibImporterFlags.SafeArrayAsSystemArray, handler, null, null, "VirtualBox", null); //using assembly name "VirtualBox" and SafeArrayAsSystemArray to be compatible to VisualStudio-Generated Interop-Assembly
            asm.Save("Interop.VirtualBox.dll");
        }
        public void BuildLib(string targetFolder)
        {
            NativeMethods.LoadTypeLibEx(VBoxWrapper.COMInterface.VBoxComUtils.GetVirtualBoxComTypeLib(), NativeMethods.RegKind.RegKind_None, out _typeLibInMemory);
            if (_typeLibInMemory == null)
            {
                throw new DllNotFoundException("Could not load Virtualbox-Typelibrary.");
            }


            TypeLibConverter       converter = new TypeLibConverter();
            ConversionEventHandler handler   = new ConversionEventHandler();

            AssemblyBuilder asm = converter.ConvertTypeLibToAssembly(_typeLibInMemory, "Interop.VirtualBox.dll", TypeLibImporterFlags.SafeArrayAsSystemArray, handler, null, null, "VirtualBox", null); //using assembly name "VirtualBox" and SafeArrayAsSystemArray to be compatible to VisualStudio-Generated Interop-Assembly

            asm.Save("Interop.VirtualBox.dll");
        }
コード例 #4
0
        /// <summary>
        /// Gets an assembly used to interop with the objects defined in the type
        /// library.
        /// </summary>
        /// <param name="typeLibraryName">
        ///		Name of the type library such as SHDocVw.dll
        /// </param>
        /// <returns>
        ///		Returns the assembly if found/created otherwise null.
        /// </returns>
        public static Assembly GetAssemblyForTypeLib(string typeLibraryName)
        {
            object typeLib = null;

            LoadTypeLibEx(typeLibraryName, RegKind.RegKind_None, out typeLib);

            if (typeLib == null)
            {
                return(null);
            }

            TypeLibConverter       converter    = new TypeLibConverter();
            ConversionEventHandler eventHandler = new ConversionEventHandler();
            AssemblyBuilder        asm          = converter.ConvertTypeLibToAssembly(typeLib, "Interop." + typeLibraryName, 0, eventHandler, null, null, null, null);

            return(asm);
        }
コード例 #5
0
    public static void Main()
    {
        Object typeLib;

        LoadTypeLibEx("SHDocVw.dll", RegKind.RegKind_None, out typeLib);

        if (typeLib == null)
        {
            Console.WriteLine("LoadTypeLibEx failed.");
            return;
        }

        TypeLibConverter       converter    = new TypeLibConverter();
        ConversionEventHandler eventHandler = new ConversionEventHandler();
        AssemblyBuilder        asm          = converter.ConvertTypeLibToAssembly(typeLib, "ExplorerLib.dll", 0, eventHandler, null, null, null, null);

        asm.Save("ExplorerLib.dll");
    }
コード例 #6
0
        private DLLModel convertDLLToManaged(DLLModel dLLModel)
        {
            Object typeLib;
            LoadTypeLibEx(dLLModel.getFullyQualifiedPath(), RegKind.RegKind_None, out typeLib);

            if (typeLib == null)
            {
                Console.WriteLine("LoadTypeLibEx failed.");
            }

            TypeLibConverter converter = new TypeLibConverter();
            ConversionEventHandler eventHandler = new ConversionEventHandler();

            string newDllName = dLLModel.getDllFileName()
                + "_converted.dll";
            AssemblyBuilder asm = converter.ConvertTypeLibToAssembly(typeLib, newDllName, 0, eventHandler, null, null, null, null);

            asm.Save(newDllName);
            DLLModel newdLLModel = new DLLModel(AppDomain.CurrentDomain.BaseDirectory + newDllName);
            return newdLLModel;
        }
コード例 #7
0
ファイル: TDxWWInput.cs プロジェクト: paladin74/Dapple
            private bool InitializeTDxInputWrapper()
            {
                bool bReturn = false;
                Object typeLib = null;
                try
                {
                    //get Com-Server from Registry
                    RegistryKey regKey
                       = Registry.LocalMachine.OpenSubKey("Software\\Classes\\CLSID\\{82C5AB54-C92C-4D52-AAC5-27E25E22604C}\\InprocServer32", false);

                          if (regKey != null)
                          {
                              string strTypeLibName = regKey.GetValue("").ToString();
                              regKey.Close();

                              LoadTypeLibEx(strTypeLibName
                                                 , RegKind.RegKind_None
                                                 , out typeLib);
                          }
                          else
                          {
                              // --- No registry set, there must be no 3DConnexion ---
                              return false;
                          }
                }
                catch (Exception)
                {
                }

                if (typeLib == null)
                {
                    Console.WriteLine("LoadTypeLibEx failed.");
                    throw new NotSupportedException("Com- Server not found.");
                }

                TypeLibConverter converter = new TypeLibConverter();
                ConversionEventHandler eventHandler = new ConversionEventHandler();
                m_Assembly = converter.ConvertTypeLibToAssembly(typeLib, "Import3DxInputAssembly.dll", 0, eventHandler, null, null, null, null);

                //Type[] ExpTypes = m_Assembly.GetTypes();
                try
                {
                    m_OSimpleDevice = m_Assembly.CreateInstance("Import3DxInputAssembly.DeviceClass");
                }
                catch
                {
                    //int nTest;
                }

                if (m_OSimpleDevice != null)
                {
                    Type TheType = m_OSimpleDevice.GetType();
                    //MethodInfo[] TheMethods = TheType.GetMethods();
                    MethodInfo method = TheType.GetMethod("get_Sensor");
                    m_OSensor = method.Invoke(m_OSimpleDevice, null);  // kein Parameter

                    method = TheType.GetMethod("get_Keyboard");
                    m_OKeyboard = method.Invoke(m_OSimpleDevice, null);

                    TheType = m_OKeyboard.GetType();
                    //TheMethods = TheType.GetMethods();
                    bReturn = true;
                }

                return bReturn;
            }
コード例 #8
0
        public string Import(ProjectReference refinfo, Project project)
        {
            RegistryKey root = Registry.ClassesRoot;
            RegistryKey typelibsKey = root.OpenSubKey("TypeLib");
            int index = refinfo.Reference.LastIndexOf("{");
            if (index < 0) {
                return null;
            }
            RegistryKey typelibKey = typelibsKey.OpenSubKey(refinfo.Reference.Substring(index, refinfo.Reference.Length - index));
            if (typelibKey == null) {
                return null;
            }
            string[] versions = typelibKey.GetSubKeyNames();

            if (versions.Length <= 0) {
                return null;
            }
            // Use the last version
            string version = versions[versions.Length - 1];
            RegistryKey versionKey = typelibKey.OpenSubKey(version);

            string tlbname = (string)versionKey.GetValue(null);

            string tlpath = GetTypelibPath(versionKey);
            if (tlpath == null) {
                return null;
            }
            string proxyfilename = "Interop." + Path.GetFileNameWithoutExtension(tlpath) + ".dll";

            AbstractProjectConfiguration ac = (AbstractProjectConfiguration)project.ActiveConfiguration;
            string fullpath = Path.Combine(ac.OutputDirectory,proxyfilename);

            if (!File.Exists(fullpath)) {
                string saveCurrDir = Directory.GetCurrentDirectory();
                if (!Directory.Exists(ac.OutputDirectory)) {
                    Directory.CreateDirectory(ac.OutputDirectory);
                }
                Directory.SetCurrentDirectory(ac.OutputDirectory);
                if (!ImportTypelibUsingTlbImpCode(tlpath, ac.OutputDirectory, proxyfilename)) {

                    MessageBox.Show("Cannot import type library using .Net SDK 1.0. Some, but not all type libraries can succesfully be imported without it. ",
                                        ".Net SDK 1.0 not present ?",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning,
                                        MessageBoxDefaultButton.Button1);

                    Object typeLib;
                    LoadTypeLibEx(tlpath, RegKind.RegKind_None, out typeLib);

                    if( typeLib == null ) {
                        throw new System.Exception("LoadTypeLibEx failed.");
                    }

                    TypeLibConverter converter = new TypeLibConverter();
                    ConversionEventHandler eventHandler = new ConversionEventHandler();

                    AssemblyBuilder asm = converter.ConvertTypeLibToAssembly( typeLib,
                                                                             proxyfilename, 0, eventHandler, null, null,
                                                                             Marshal.GetTypeLibName((UCOMITypeLib)typeLib), null );

                    asm.Save( proxyfilename );

                }
                Directory.SetCurrentDirectory(saveCurrDir);
            }
            return fullpath;
        }