internal bool InitializeWithPath(TaskLoggingHelper log, string path, ITaskItem originalTaskItem, string targetProcessorArchitecture)
        {
            Microsoft.Build.Shared.ErrorUtilities.VerifyThrowArgumentNull(path, "path");
            this.taskItem    = originalTaskItem;
            this.typeLibPath = ComReference.StripTypeLibNumberFromPath(path, new Microsoft.Build.Shared.FileExists(File.Exists));
            string str = targetProcessorArchitecture;

            if (str != null)
            {
                if (!(str == "AMD64") && !(str == "IA64"))
                {
                    if (str == "x86")
                    {
                        this.typeLibPointer = (ITypeLib)Microsoft.Build.Tasks.NativeMethods.LoadTypeLibEx(path, 0x20);
                        goto Label_00A2;
                    }
                    if (str == "MSIL")
                    {
                    }
                }
                else
                {
                    this.typeLibPointer = (ITypeLib)Microsoft.Build.Tasks.NativeMethods.LoadTypeLibEx(path, 0x40);
                    goto Label_00A2;
                }
            }
            this.typeLibPointer = (ITypeLib)Microsoft.Build.Tasks.NativeMethods.LoadTypeLibEx(path, 2);
Label_00A2:
            try
            {
                ComReference.GetTypeLibAttrForTypeLib(ref this.typeLibPointer, out this.attr);
                if (!ComReference.GetTypeLibNameForITypeLib(log, this.typeLibPointer, this.GetTypeLibId(log), out this.typeLibName))
                {
                    this.ReleaseTypeLibPtr();
                    return(false);
                }
            }
            catch (COMException)
            {
                this.ReleaseTypeLibPtr();
                throw;
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize the object with a type library path
        /// </summary>
        internal bool InitializeWithPath(TaskLoggingHelper log, bool silent, string path, ITaskItem originalTaskItem, string targetProcessorArchitecture)
        {
            ErrorUtilities.VerifyThrowArgumentNull(path, nameof(path));

            this.taskItem = originalTaskItem;

            // Note that currently we DO NOT remap file ADO references. This is because when pointing to a file on disk,
            // it seems unnatural to remap it to something else - a file reference means "use THIS component".
            // This is still under debate though, and may be revised later.

            // save both the stripped and full path in our object -- for the most part we just need the stripped path, but if
            // we're using tlbimp.exe, we need to pass the full path w/ type lib number to it, or it won't generate the interop
            // assembly correctly.
            this.fullTypeLibPath     = path;
            this.strippedTypeLibPath = ComReference.StripTypeLibNumberFromPath(path, File.Exists);

            // use the unstripped path to actually load the library
            switch (targetProcessorArchitecture)
            {
            case ProcessorArchitecture.AMD64:
            case ProcessorArchitecture.IA64:
                this.typeLibPointer = (ITypeLib)NativeMethods.LoadTypeLibEx(path, (int)NativeMethods.REGKIND.REGKIND_LOAD_TLB_AS_64BIT);
                break;

            case ProcessorArchitecture.X86:
                this.typeLibPointer = (ITypeLib)NativeMethods.LoadTypeLibEx(path, (int)NativeMethods.REGKIND.REGKIND_LOAD_TLB_AS_32BIT);
                break;

            case ProcessorArchitecture.ARM:
            case ProcessorArchitecture.MSIL:
            default:
                // Transmit the flag directly from the .targets files and rely on tlbimp.exe to produce a good error message.
                this.typeLibPointer = (ITypeLib)NativeMethods.LoadTypeLibEx(path, (int)NativeMethods.REGKIND.REGKIND_NONE);
                break;
            }

            try
            {
                // get the type lib attributes from the retrieved interface pointer.
                // do NOT remap file ADO references, since we'd end up with a totally different reference than specified.
                ComReference.GetTypeLibAttrForTypeLib(ref this.typeLibPointer, out this.attr);

                // get the type lib name from the retrieved interface pointer
                if (!ComReference.GetTypeLibNameForITypeLib(
                        log,
                        silent,
                        this.typeLibPointer,
                        GetTypeLibId(log),
                        out this.typeLibName))
                {
                    ReleaseTypeLibPtr();
                    return(false);
                }
            }
            catch (COMException)
            {
                ReleaseTypeLibPtr();
                throw;
            }

            return(true);
        }