我怎样才能了解无证.NET / COM库函数? [英] How can I find out about undocumented .NET / COM library functions?

查看:266
本文介绍了我怎样才能了解无证.NET / COM库函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能找到的属性和COM的方法的对象从一些.NET函数,这似乎并没有被记录返回?

How can I find out the properties and methods of COM objects returned from some .NET functions, which do not appear to be documented?

在特定的例子中,我看着看着,我插入图片插入Excel中使用的函数,如:

In the particular example I'm looking at, I'm inserting a picture into Excel using a function like:

Set NewPic = ActiveSheet.Pictures.Insert(FileName)

(见SO寄出对这段<一个href="http://stackoverflow.com/questions/521979/is-is-possible-to-insert-an-image-into-an-excel-cell-via-com">here.)

不过, MSDN文档此功能只说Worksheet.Pictures返回一个对象,当我把手表上的变量在调试过程中它的类型是系统.__ ComObject。我可以找出其他的属性和功能可能是用于该类别(例如,我想修改的替代文本图片)?如何将谁发现了甚至已经知道这件事了插入函数的人?

However, the MSDN documentation for this function only says that Worksheet.Pictures returns an Object, and when I put a watch on the variable during debugging its type is System.__ComObject. Can I find out what other properties and functions might be available for that class (for example, I want to modify the alternative text for the picture)? How would the person who found out about the Insert function even have known about it?

在MSDN文档也往往会说这样的功能,他们是不打算直接从您的code所用的,但让我们忽略了现在...

The MSDN doc also tends to say of such functions that they are "not intended to be used directly from your code", but let's ignore that for now...

谢谢!


编辑:好吧,我设法至少要回答我的具体问题。而不是使用 Worksheet.Pictures.Insert ,你可以使用 Worksheet.Shapes.AddPicture 返回正确的(记录) Excel.Shape类:

Well, I managed to answer my specific question at least. Instead of using Worksheet.Pictures.Insert, you can use Worksheet.Shapes.AddPicture to return a proper (documented) Excel.Shape class:

pic = range.Worksheet.Shapes.AddPicture(tmpFile, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, range.Left, range.Top, image.Width, image.Height)
pic.AlternativeText = "Help!"

会不会让感兴趣的未公开的函数,虽然任何资源。

Would still be interested in any resources for undocumented functions though.

推荐答案

要找到这些东西的一种方法是使用 OLEVIEW 工具(你可以从微软下载<一href="http://www.microsoft.com/downloads/details.aspx?familyid=5233b70d-d9b2-4cb5-aeb6-45664be858b6&displaylang=en"相对=nofollow>这里)。该工具允许您查看COM类型库。类型库(假定的COM组件提供类型库信息供应商)包含有关应用程序或库中暴露出来的COM类的接口,方法和属性的信息。

One way to find these things out is to use the OleView tool (which you can download from Microsoft here). This tool allows you to view COM Type Libraries. The Type Library (assuming the vendor of the COM component provided type library information) contains information about the interfaces and the methods and properties of the COM classes exposed by an application or library.

例如,我的机器上,我可以看到的类型库 C:\ Program Files文件\微软的Office \ OFFICE12 \ EXCEL.EXE ,看看有什么COM对象用Excel,和它们的属性和方法暴露。 OLEVIEW 显示IDL(接口描述语言),这或多或少的C函数原型上涨了额外的属性)。

For example, on my machine, I can view the Type Library for C:\Program Files\Microsoft Office\Office12\EXCEL.EXE and see what COM objects are exposed by Excel, and their properties and methods. OleView displays information in IDL (Interface Description Language), which is more or less a C function prototype with extra attributes tacked on).

这是IDL声明我得到了使用 OLEVIEW __ Worksheet.Pictures 属性:

This is the IDL declaration I got using OleView for the __Worksheet.Pictures property:

    [id(0x00000303), hidden, helpcontext(0x00010303)]
    HRESULT Pictures(
                    [in, optional] VARIANT Index, 
                    [in, lcid] long lcid, 
                    [out, retval] IDispatch** RHS);

注意隐藏属性的声明。这意味着它不会被大多数IDE的显示(并且是一个很好的提示,不要依赖此方法始终存在 - 微软可能会在以后版本的Excel中删除)。

Note the hidden attribute on the declaration. This means it won't be displayed by most IDE's (and is a good hint to not rely on this method always existing - Microsoft could remove it in a later version of Excel).

现在怎么样了图片类?下面是完整的IDL:

Now what about the Pictures class? Here is the full IDL:

[
  uuid(000208A7-0000-0000-C000-000000000046),
  helpcontext(0x00020067),
  hidden
]
dispinterface Pictures {
    properties:
    methods:
        [id(0x60000000), restricted]
        void QueryInterface(
                        [in] GUID* riid, 
                        [out] void** ppvObj);
        [id(0x60000001), restricted]
        unsigned long AddRef();
        [id(0x60000002), restricted]
        unsigned long Release();
        [id(0x60010000), restricted]
        void GetTypeInfoCount([out] unsigned int* pctinfo);
        [id(0x60010001), restricted]
        void GetTypeInfo(
                        [in] unsigned int itinfo, 
                        [in] unsigned long lcid, 
                        [out] void** pptinfo);
        [id(0x60010002), restricted]
        void GetIDsOfNames(
                        [in] GUID* riid, 
                        [in] char** rgszNames, 
                        [in] unsigned int cNames, 
                        [in] unsigned long lcid, 
                        [out] long* rgdispid);
        [id(0x60010003), restricted]
        void Invoke(
                        [in] long dispidMember, 
                        [in] GUID* riid, 
                        [in] unsigned long lcid, 
                        [in] unsigned short wFlags, 
                        [in] DISPPARAMS* pdispparams, 
                        [out] VARIANT* pvarResult, 
                        [out] EXCEPINFO* pexcepinfo, 
                        [out] unsigned int* puArgErr);
        [id(0x00000094), propget, helpcontext(0x00010094)]
        Application* Application();
        [id(0x00000095), propget, helpcontext(0x00010095)]
        XlCreator Creator();
        [id(0x00000096), propget, helpcontext(0x00010096)]
        IDispatch* Parent();
        [id(0x00010003), restricted, hidden]
        void _Dummy3();
        [id(0x0000025a), helpcontext(0x0001025a)]
        VARIANT BringToFront();
        [id(0x00000227), helpcontext(0x00010227)]
        VARIANT Copy();
        [id(0x000000d5), helpcontext(0x000100d5)]
        VARIANT CopyPicture(
                        [in, optional, defaultvalue(2)] XlPictureAppearance Appearance, 
                        [in, optional, defaultvalue(-4147)] XlCopyPictureFormat Format);
        [id(0x00000235), helpcontext(0x00010235)]
        VARIANT Cut();
        [id(0x00000075), helpcontext(0x00010075)]
        VARIANT Delete();
        [id(0x0000040f), helpcontext(0x0001040f)]
        IDispatch* Duplicate();
        [id(0x00000258), propget, helpcontext(0x00010258)]
        VARIANT_BOOL Enabled();
        [id(0x00000258), propput, helpcontext(0x00010258)]
        void Enabled([in] VARIANT_BOOL rhs);
        [id(0x0000007b), propget, helpcontext(0x0001007b)]
        double Height();
        [id(0x0000007b), propput, helpcontext(0x0001007b)]
        void Height([in] double rhs);
        [id(0x0001000c), restricted, hidden]
        void _Dummy12();
        [id(0x0000007f), propget, helpcontext(0x0001007f)]
        double Left();
        [id(0x0000007f), propput, helpcontext(0x0001007f)]
        void Left([in] double rhs);
        [id(0x0000010d), propget, helpcontext(0x0001010d)]
        VARIANT_BOOL Locked();
        [id(0x0000010d), propput, helpcontext(0x0001010d)]
        void Locked([in] VARIANT_BOOL rhs);
        [id(0x0001000f), restricted, hidden]
        void _Dummy15();
        [id(0x00000254), propget, hidden, helpcontext(0x00010254)]
        BSTR OnAction();
        [id(0x00000254), propput, hidden, helpcontext(0x00010254)]
        void OnAction([in] BSTR rhs);
        [id(0x00000269), propget, helpcontext(0x00010269)]
        VARIANT Placement();
        [id(0x00000269), propput, helpcontext(0x00010269)]
        void Placement([in] VARIANT rhs);
        [id(0x0000026a), propget, helpcontext(0x0001026a)]
        VARIANT_BOOL PrintObject();
        [id(0x0000026a), propput, helpcontext(0x0001026a)]
        void PrintObject([in] VARIANT_BOOL rhs);
        [id(0x000000eb), helpcontext(0x000100eb)]
        VARIANT Select([in, optional] VARIANT Replace);
        [id(0x0000025d), helpcontext(0x0001025d)]
        VARIANT SendToBack();
        [id(0x0000007e), propget, helpcontext(0x0001007e)]
        double Top();
        [id(0x0000007e), propput, helpcontext(0x0001007e)]
        void Top([in] double rhs);
        [id(0x00010016), restricted, hidden]
        void _Dummy22();
        [id(0x0000022e), propget, helpcontext(0x0001022e)]
        VARIANT_BOOL Visible();
        [id(0x0000022e), propput, helpcontext(0x0001022e)]
        void Visible([in] VARIANT_BOOL rhs);
        [id(0x0000007a), propget, helpcontext(0x0001007a)]
        double Width();
        [id(0x0000007a), propput, helpcontext(0x0001007a)]
        void Width([in] double rhs);
        [id(0x0000026e), propget, helpcontext(0x0001026e)]
        long ZOrder();
        [id(0x000005f8), propget, helpcontext(0x000105f8)]
        ShapeRange* ShapeRange();
        [id(0x00000080), propget, helpcontext(0x00010080)]
        Border* Border();
        [id(0x00000081), propget, helpcontext(0x00010081)]
        Interior* Interior();
        [id(0x00000067), propget, helpcontext(0x00010067)]
        VARIANT_BOOL Shadow();
        [id(0x00000067), propput, helpcontext(0x00010067)]
        void Shadow([in] VARIANT_BOOL rhs);
        [id(0x00000105), propget, helpcontext(0x00010105)]
        BSTR Formula();
        [id(0x00000105), propput, helpcontext(0x00010105)]
        void Formula([in] BSTR rhs);
        [id(0x000000b5), helpcontext(0x000100b5)]
        Picture* Add(
                        [in] double Left, 
                        [in] double Top, 
                        [in] double Width, 
                        [in] double Height);
        [id(0x00000076), propget, helpcontext(0x00010076)]
        long Count();
        [id(0x0000002e), helpcontext(0x0001002e)]
        GroupObject* Group();
        [id(0x000000fc), helpcontext(0x000100fc)]
        Picture* Insert(
                        [in] BSTR Filename, 
                        [in, optional] VARIANT Converter);
        [id(0x000000aa), helpcontext(0x000100aa)]
        IDispatch* Item([in] VARIANT Index);
        [id(0xfffffffc), helpcontext(0x0000fffc)]
        IUnknown* _NewEnum();
        [id(0x000000d3), helpcontext(0x000100d3)]
        Picture* Paste([in, optional] VARIANT Link);

在此,你可以推测,图片接口有一个剪切删除的方法,以及一个项目属性,等等。但是请注意,这个接口也被标记隐藏,这(再次)是,你应该没有真正使用它一个很好的迹象(是的,我知道你忽略了警告,但我第二米奇小麦的评论,这通常是一个坏主意,使用隐藏类,因为它们通常意味着应用程序自身的内部使用,如有更改恕不另行通知。)

From this, you can surmise that the Pictures interface has a Cut and Delete method, as well as an Item property, among others. However, note that this interface is also marked hidden, which (again) is a good indication that you shouldn't really be using it (yes, I know you were ignoring that warning, but I second Mitch Wheat's comment that it's generally a bad idea to use hidden classes, because they are usually meant for the application's own internal use and are subject to change without notice.)

这篇关于我怎样才能了解无证.NET / COM库函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆