如何找到有关未记录的.NET / COM库函数? [英] How can I find out about undocumented .NET / COM library functions?

查看:391
本文介绍了如何找到有关未记录的.NET / COM库函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找出从一些.NET函数返回的COM对象的属性和方法,它们似乎没有被记录?



在特定示例中我在使用下面的函数插入图片到Excel:

 设置NewPic = ActiveSheet.Pictures.Insert (FileName)

(请参阅此 / 521979 / is-is-is-is-is-be-to-insert-an-image-into-an-excel-cell-via-com>这里。)



但是, MSDN文档的这个功能只说Worksheet.Pictures返回一个对象,当我把一个监视变量在调试它的类型是System .__ ComObject。我可以找出什么其他属性和函数可能可用于该类(例如,我想修改图片的替代文本)?发现 Insert 函数的人怎么会知道呢?



MSDN文档也倾向于



谢谢!

感谢您的支持!




编辑:我设法回答了我的具体问题。而不是使用 Worksheet.Pictures.Insert ,您可以使用 Worksheet.Shapes.AddPicture 返回一个正确的Excel.Shape类:

  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!

尽管


仍然对未记录函数的任何资源感兴趣。找到这些东西的一种方法是使用 OleView 工具(你可以从Microsoft下载 a href =http://www.microsoft.com/downloads/details.aspx?familyid=5233b70d-d9b2-4cb5-aeb6-45664be858b6&displaylang=en =nofollow noreferrer>此处)。此工具允许您查看COM类型库。类型库(假设COM组件的供应商提供类型库信息)包含关于应用程序或库所暴露的COM类的接口以及方法和属性的信息。



例如,在我的机器上,我可以查看 C:\Program Files\ Microsoft Office \Office12 \EXCEL.EXE 的类型库, COM对象由Excel公开,及其属性和方法。 OleView 在IDL(接口描述语言)中显示信息,它或多或少是带有额外属性的C函数原型。)



这是我使用 OleView __ Worksheet.Pictures 属性使用的IDL声明:

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

请注意声明上的 hidden 属性。这意味着它不会显示大多数IDE(并且是一个很好的提示,不依赖这种方法总是存在 - 微软可以删除它在Excel的更高版本)。



现在 Pictures 课程怎么样?这是完整的IDL:

  [
uuid(000208A7-0000-0000-C000-000000000046),
helpcontext(0x00020067),
hidden
]
dispinterface图片{
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] 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();
[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外观
[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锁定([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),restrict,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公式();
[id(0x00000105),propput,helpcontext(0x00010105)]
void公式([in] BSTR rhs);
[id(0x000000b5),helpcontext(0x000100b5)]
图片*添加(
[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)]
图片*插入(
[in] BSTR文件名,
[in,可选] VARIANT Converter);
[id(0x000000aa),helpcontext(0x000100aa)]
IDispatch * Item([in] VARIANT Index);
[id(0xfffffffc),helpcontext(0x0000fffc)]
IUnknown * _NewEnum();
[id(0x000000d3),helpcontext(0x000100d3)]
图片*粘贴([可选] VARIANT链接);

从这里,你可以推测 Pictures 接口有 Cut Delete 方法,以及属性,等等。但是,请注意,此接口也标记为 hidden ,这(再次)是一个很好的指示,你不应该真正使用它(是的,我知道你忽略了警告,但我第二次Mitch Wheat的评论,使用隐藏类通常是一个坏主意,因为它们通常是为应用程序自己的内部使用,如有更改,恕不另行通知。)


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

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)

(See the SO post on this here.)

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?

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...

Thanks!


Edit: 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.

解决方案

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.

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).

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);

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).

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天全站免登陆