internal unsafe string GetClassName(object component)
        {
            string name = null;

            // does IVsPerPropretyBrowsing supply us a name?
            if (component is VSSDK.IVsPerPropertyBrowsing)
            {
                HRESULT hr = ((VSSDK.IVsPerPropertyBrowsing)component).GetClassName(ref name);
                if (hr.Succeeded() && name != null)
                {
                    return(name);
                }
                // otherwise fall through...
            }

            Oleaut32.ITypeInfo pTypeInfo = Com2TypeInfoProcessor.FindTypeInfo(component, true);

            if (pTypeInfo is null)
            {
                return(string.Empty);
            }

            using var nameBstr = new BSTR();
            pTypeInfo.GetDocumentation(DispatchID.MEMBERID_NIL, &nameBstr, null, null, null);
            return(nameBstr.String.TrimStart('_').ToString());
        }
        public unsafe void ITypeInfo_GetNames_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            BSTR *rgszNames = stackalloc BSTR[2];

            rgszNames[0] = new BSTR("Name1");
            rgszNames[1] = new BSTR("Name2");
            uint cNames = 0;

            hr = typeInfo.GetNames((DispatchID)4, rgszNames, 2u, &cNames);
            Assert.Equal(HRESULT.S_OK, hr);
            Assert.Equal("Width", rgszNames[0].String.ToString());
            Assert.Equal("Name2", rgszNames[1].String.ToString());
            Assert.Equal(1u, cNames);

            rgszNames[0].Dispose();
            rgszNames[1].Dispose();
        }
Exemple #3
0
    public void BSTR_ToString()
    {
        BSTR bstr = (BSTR)Marshal.StringToBSTR("hi");

        try
        {
            Assert.Equal("hi", bstr.ToString());
        }
        finally
        {
            PInvoke.SysFreeString(bstr);
        }
    }
Exemple #4
0
        public void allocFreeTest3()
        {
            string managed = " my string 123 ";

            UnmanagedString uns;

            using (uns = new UnmanagedString(managed, UnmanagedString.SType.BSTR)) {
                BSTR actual = uns;
                Assert.Equal(managed.Length, ((string)actual).Length);
                Assert.Equal(UnmanagedString.SType.BSTR, uns.Type);
            }

            Assert.Equal(IntPtr.Zero, (IntPtr)uns);
        }
Exemple #5
0
    public unsafe void BSTR_AsSpan()
    {
        BSTR bstr = (BSTR)Marshal.StringToBSTR("hi");

        try
        {
            ReadOnlySpan <char> span = bstr.AsSpan();
            Assert.Equal(2, span.Length);
            Assert.Equal('h', span[0]);
            Assert.Equal('i', span[1]);
        }
        finally
        {
            PInvoke.SysFreeString(bstr);
        }
    }
        public unsafe void ITypeInfo_GetMops_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            var mops = new BSTR("Mops");

            hr = typeInfo.GetMops((DispatchID)4, &mops);
            Assert.Equal(HRESULT.S_OK, hr);
            Assert.Empty(mops.String.ToString());
        }
Exemple #7
0
        public void echoTest3()
        {
            using (var l = new ConariL(UNLIB_DLL))
            {
                string exp = "my string-123 !";

                using (var uns = new UnmanagedString(exp, UnmanagedString.SType.BSTR))
                {
                    BSTR bstr = uns;

                    Assert.AreEqual(exp, l.DLR.get_BSTRVal <BSTR>(bstr));
                    Assert.AreEqual(exp, l.bind <Func <BSTR, BSTR> >("get_BSTRVal")(bstr));

                    var dyn = l.bind(Dynamic.GetMethodInfo(typeof(BSTR), typeof(BSTR)), "get_BSTRVal");
                    Assert.AreEqual(exp, (BSTR)dyn.dynamic.Invoke(null, new object[] { bstr }));
                }
            }
        }
        public unsafe void ITypeInfo_GetDllEntry_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            var    dllName  = new BSTR("DllName");
            var    name     = new BSTR("Name");
            ushort wOrdinal = ushort.MaxValue;

            hr = typeInfo.GetDllEntry((DispatchID)6, INVOKEKIND.FUNC, &dllName, &name, &wOrdinal);
            Assert.Equal(HRESULT.TYPE_E_BADMODULEKIND, hr);
            Assert.Empty(dllName.String.ToString());
            Assert.Empty(name.String.ToString());
            Assert.Equal(0u, wOrdinal);
        }
        public unsafe void ITypeInfo_GetDocumentation_Invoke_Success()
        {
            using var image = new Bitmap(16, 32);
            IPictureDisp picture  = SubAxHost.GetIPictureDispFromPicture(image);
            IDispatch    dispatch = (IDispatch)picture;
            ITypeInfo    typeInfo;
            HRESULT      hr = dispatch.GetTypeInfo(0, Kernel32.GetThreadLocale(), out typeInfo);

            Assert.Equal(HRESULT.S_OK, hr);

            using var name      = new BSTR("Name");
            using var docString = new BSTR("DocString");
            uint dwHelpContext = uint.MaxValue;

            using var helpFile = new BSTR("HelpFile");
            hr = typeInfo.GetDocumentation((DispatchID)4, &name, &docString, &dwHelpContext, &helpFile);
            Assert.Equal(HRESULT.S_OK, hr);
            Assert.Equal("Width", name.String.ToString());
            Assert.Empty(docString.String.ToString());
            Assert.Equal(0u, dwHelpContext);
            Assert.Empty(helpFile.String.ToString());
        }
 virtual HRESULT __stdcall raw_WriteLine(BSTR message)
 {
     // Convert BSTR and write to _log.
     return(S_OK);
 }
 virtual HRESULT STDMETHODCALLTYPE GetHelpFile(
     /* [out] */ BSTR *pBstrHelpFile) = 0;
 virtual HRESULT STDMETHODCALLTYPE GetDescription(
     /* [out] */ BSTR *pBstrDescription) = 0;
 virtual HRESULT STDMETHODCALLTYPE GetSource(
     /* [out] */ BSTR *pBstrSource) = 0;