Esempio n. 1
0
        public unsafe void IsName()
        {
            HResult result = LoadStdOle2(out ITypeLib typeLib);

            result.Should().Be(HResult.S_OK);
            typeLib.Should().NotBeNull();

            string      name       = "ifont";
            char *      nameBuffer = stackalloc char[name.Length + 1];
            Span <char> nameSpan   = new Span <char>(nameBuffer, name.Length);

            name.AsSpan().CopyTo(nameSpan);
            nameBuffer[name.Length] = '\0';

            result = typeLib.IsName(
                nameBuffer,
                lHashVal: 0,
                out Boolean32 foundName);

            result.Should().Be(HResult.S_OK);
            foundName.Should().Be((Boolean32)true);

            // Find gives back the right casing
            nameSpan.ToString().Should().Be("IFont");
        }
Esempio n. 2
0
        public unsafe void GetDocumentation()
        {
            HResult result = LoadStdOle2(out ITypeLib typeLib);

            result.Should().Be(HResult.S_OK);
            typeLib.Should().NotBeNull();

            uint typeInfoCount = typeLib.GetTypeInfoCount();

            typeInfoCount.Should().Be(42);

            var docs = new List <(string name, string doc, string helpFile)>();

            for (int i = 0; i < typeInfoCount; i++)
            {
                BasicString name;
                BasicString doc;
                BasicString helpFile;
                result = typeLib.GetDocumentation(
                    index: i,
                    &name,
                    &doc,
                    out uint _,
                    &helpFile);

                result.Should().Be(HResult.S_OK);
                docs.Add((name.ToStringAndFree(), doc.ToStringAndFree(), helpFile.ToStringAndFree()));
            }

            docs[34].Should().Be(("IPicture", "Picture Object", null));
        }
Esempio n. 3
0
        public unsafe void LoadFromRegistry()
        {
            HResult result = LoadStdOle2(out ITypeLib typeLib);

            result.Should().Be(HResult.S_OK);
            typeLib.Should().NotBeNull();

            uint typeInfoCount = typeLib.GetTypeInfoCount();

            typeInfoCount.Should().Be(42);

            TypeLibraryAttributes *attributes;

            result = typeLib.GetLibAttr(&attributes);
            result.Should().Be(HResult.S_OK);

            attributes->MajorVerNum.Should().Be(2);
            attributes->MinorVerNum.Should().Be(0);
            attributes->LocaleId.Should().Be((LocaleId)0);
            attributes->LibraryFlags.Should().Be(LibraryFlags.HasDiskImage);
            attributes->Guid.Should().Be(IID_StdOle);
            attributes->SystemKind.Should().Be(Environment.Is64BitProcess ? SystemKind.Win64 : SystemKind.Win32);

            typeLib.ReleaseTLibAttr(attributes);
        }
Esempio n. 4
0
        public unsafe void GetVariableDescriptionsForGUID()
        {
            TypeLibTests.LoadStdOle2(out ITypeLib typeLib);
            ITypeInfo typeInfo = typeLib.GetTypeInfoByName("GUID");

            HResult result = typeInfo.GetVarDesc(0, out VARDESC * description);

            result.Should().Be(HResult.S_OK);

            // uint
            description->varkind.Should().Be(VariableKind.PerInstance);
            description->wVarFlags.Should().Be((VariableFlags)0);
            description->elemdescVar.tdesc.vt.Should().Be(VariantType.UInt32);

            typeInfo.ReleaseVarDesc(description);

            result = typeInfo.GetVarDesc(1, out description);
            result.Should().Be(HResult.S_OK);

            // ushort
            description->varkind.Should().Be(VariableKind.PerInstance);
            description->wVarFlags.Should().Be((VariableFlags)0);
            description->elemdescVar.tdesc.vt.Should().Be(VariantType.UInt16);

            typeInfo.ReleaseVarDesc(description);

            result = typeInfo.GetVarDesc(2, out description);
            result.Should().Be(HResult.S_OK);

            // ushort
            description->varkind.Should().Be(VariableKind.PerInstance);
            description->wVarFlags.Should().Be((VariableFlags)0);
            description->elemdescVar.tdesc.vt.Should().Be(VariantType.UInt16);

            typeInfo.ReleaseVarDesc(description);

            result = typeInfo.GetVarDesc(3, out description);
            result.Should().Be(HResult.S_OK);

            // Fixed 8 byte array
            description->varkind.Should().Be(VariableKind.PerInstance);
            description->wVarFlags.Should().Be((VariableFlags)0);
            description->elemdescVar.tdesc.vt.Should().Be(VariantType.CArray);
            description->elemdescVar.tdesc.Union.llpadesc->cDims.Should().Be(1);
            description->elemdescVar.tdesc.Union.llpadesc->rgbounds[0].Count.Should().Be(8);
            description->elemdescVar.tdesc.Union.llpadesc->tdescElem.vt.Should().Be(VariantType.UnsignedByte);

            typeInfo.ReleaseVarDesc(description);
        }
Esempio n. 5
0
        public unsafe void GetFunctionDescriptionsForIUnknown()
        {
            TypeLibTests.LoadStdOle2(out ITypeLib typeLib);
            ITypeInfo typeInfo = typeLib.GetTypeInfoByName("IUnknown");

            // From OleView:
            //
            // [restricted]
            // HRESULT _stdcall QueryInterface(
            //                [in] GUID* riid,
            //                [out] void** ppvObj);

            HResult result = typeInfo.GetFuncDesc(0, out FUNCDESC * description);

            result.Should().Be(HResult.S_OK);

            description->cParams.Should().Be(2);
            description->cParamsOpt.Should().Be(0);
            description->cScodes.Should().Be(0);
            description->callconv.Should().Be(CallConvention.StdCall);
            description->funckind.Should().Be(FunctionKind.PureVirtual);
            description->invkind.Should().Be(InvokeKind.Function);
            description->wFuncFlags.Should().Be(FunctionFlags.Restricted);

            // Return type
            description->elemdescFunc.tdesc.vt.Should().Be(VariantType.HResult);

            // First arg GUID*
            ELEMDESC *element = description->lprgelemdescParam;

            element->tdesc.vt.Should().Be(VariantType.Pointer);
            element->Union.paramdesc.wParamFlags.Should().Be(ParameterFlags.In);
            element->tdesc.Union.lptdesc->vt.Should().Be(VariantType.UserDefined);
            RefTypeHandle handle = element->tdesc.Union.lptdesc->Union.hreftype;

            result = typeInfo.GetRefTypeInfo(handle, out ITypeInfo userDefined);
            result.Should().Be(HResult.S_OK);
            userDefined.GetMemberName(MemberId.Nil).Should().Be("GUID");

            // Second arg void**
            element++;
            element->tdesc.vt.Should().Be(VariantType.Pointer);
            element->Union.paramdesc.wParamFlags.Should().Be(ParameterFlags.Out);
            element->tdesc.Union.lptdesc->vt.Should().Be(VariantType.Pointer);
            element->tdesc.Union.lptdesc->Union.lptdesc->vt.Should().Be(VariantType.Void);

            typeInfo.ReleaseFuncDesc(description);
        }
Esempio n. 6
0
        public unsafe void GetTypeAttributesForIUnknown()
        {
            TypeLibTests.LoadStdOle2(out ITypeLib typeLib);
            ITypeInfo typeInfo = typeLib.GetTypeInfoByName("IUnknown");

            HResult result = typeInfo.GetTypeAttr(out TYPEATTR * attributes);

            result.Should().Be(HResult.S_OK);
            Assert.True(attributes != null);

            attributes->cFuncs.Should().Be(3);
            attributes->cImplTypes.Should().Be(0);
            attributes->cVars.Should().Be(0);
            attributes->cbAlignment.Should().Be(8);
            attributes->cbSizeInstance.Should().Be(8);
            attributes->cbSizeVft.Should().Be(24);
            attributes->wMajorVerNum.Should().Be(0);
            attributes->wMinorVerNum.Should().Be(0);
            attributes->typekind.Should().Be(TypeKind.Interface);
            attributes->wTypeFlags.Should().Be(TypeFlags.Hidden);
            attributes->idldescType.Flags.Should().Be(IdlFlag.None);
            attributes->guid.Should().Be(new Guid("{00000000-0000-0000-c000-000000000046}"));
            attributes->lcid.Should().Be((LocaleId)0);
            attributes->memidConstructor.Should().Be(MemberId.Nil);
            attributes->memidDestructor.Should().Be(MemberId.Nil);
            attributes->tdescAlias.vt.Should().Be(VariantType.Empty);

            typeInfo.ReleaseTypeAttr(attributes);
        }
Esempio n. 7
0
        public unsafe void FindName()
        {
            HResult result = LoadStdOle2(out ITypeLib typeLib);

            result.Should().Be(HResult.S_OK);
            typeLib.Should().NotBeNull();

            string      name       = "picture";
            char *      nameBuffer = stackalloc char[name.Length + 1];
            Span <char> nameSpan   = new Span <char>(nameBuffer, name.Length);

            name.AsSpan().CopyTo(nameSpan);
            nameBuffer[name.Length] = '\0';

            IntPtr *  typeInfos = stackalloc IntPtr[1];
            MemberId *memberIds = stackalloc MemberId[1];
            ushort    found     = 1;

            result = typeLib.FindName(
                nameBuffer,
                lHashVal: 0,
                typeInfos,
                memberIds,
                &found);

            result.Should().Be(HResult.S_OK);
            found.Should().Be(1);
            memberIds[0].Should().Be(new MemberId {
                Value = -1
            });
            typeInfos[0].Should().NotBe(IntPtr.Zero);
            Marshal.Release(typeInfos[0]);

            // Find gives back the right casing
            nameSpan.ToString().Should().Be("Picture");
        }
        public void WindowsErrorToHresultMappings(WindowsError error, HResult expected)
        {
            HResult result = error.ToHResult();

            result.Should().Be(expected);
        }