I'm using a badly documented library ("Acrobat Acrobat 10.0") to modify PDF documents using VBA.
In order to perform this modification, I use an Object (JavaScript Object), which represents a VBA interface to a JavaScript library. My problem: I can't find any documentation online. I can find the corresponding JavaScript documentation, but nothing that describes what I need/in a way that I need it.
Is it possible to iterate over the methods/properties of an 'anonymous' object?
If you can early-bind (Tools -> References...) the library, then you can already use the Object Browser (F2) to browse its modules and all the members it exposes, and read every member's docstring if it exists.
If you can't early-bind the library and can only work with Object, you're pretty much stuck: the only way to iterate members of a library is to load that library; VBA doesn't have native support for reflection, but with Rubberduck's experimental COM API you can definitely do that... as long as the library is referenced.
Related
I have referenced the SketchUp.exe into a project or at times an extracted TLB from the SketchUp.exe and can see the object model but cannot create an instance of any object in it.
I found out it may be a non-shared object or set to PublicNoncreatable and thus unlike AutoCAD or Excel I cannot create object instances.
When working with Adobe Acrobat I found it had the same problem but had a non-viewable object name which allowed instancing its objects.
Maybe SketchUp also has a completely hidden object or method that allows this. In the mean time is there a way to apply and instance of the object by overriding its non-share status as shared?
SketchUp's COM API is no longer supported. You may want to take a look at the new C API.
For instance, at first I thought that what went in the parentheses was the library and class separated by a period (Ex: "Scripting.Dictionary", "Scripting.FileSystemObject". However, when you use it for internet explorer it is "InternetExplorer.Application" instead of "SHDocVw.InternetExplorer". Is the syntax not standard and something you just need to look up every time? I will use early binding anyways but I'm just curious.
The string used as a parameter to CreateObject() is what's known as a programmatic identifier or "ProgId". COM classes identify themselves using a CLSID, or what is essentially a GUID. But rather than having to remember and type the CLSID for the FileSystemObject COM class whenever you need to instantiate the COM object (which is {0D43FE01-F093-11CF-8940-00A0C9054228}, by the way), COM allows for the specification of a ProgId string.
You can examine the contents of the HKEY_CLASSES_ROOT\CLSID registry key to see all COM classes available on your PC. Here's the CLSID for the FileSystemObject class, showing the ProgID:
Tools like OleView or NirSoft's ActiveXHelper make finding ProgIds much easier. Other languages require you to jump through hoops to create COM objects. But the VB family of languages is "COM aware" and provides the necessary utilities to easily create and work with COM components without having to worry about IIDs, CLSIDs, Type Libraries, and other "COM" mumbo jumbo. In VB, when you add a "Reference", you're referencing a Type Library. When you call CreateObject(<string>), you're telling Windows to look up the CLSID of the COM class with a ProgId of <string>. They're just simpler, cleaner ways to interface with the COM world.
To (try to) answer your question, a ProgId can really be anything the creator of the COM object chooses. It's typically "<COM Library>.<COM Class>" but that's not always the case. Often version numbers are included. "MSMXL2.DOMDocument.6.0", for example, includes a version number for both the library and the class. Other times, there's no library at all (CreateObject("htmlfile"), for example). So, unfortunately, there's no perfect standard here.
It depends on how you are accessing the library.
NOTE: This will work in Visual Basic or VBScript
fso = CreateObject("Scripting.FileSystemObject")
Scripting is the name of the type library, and FileSystemObject is the name of the object of which you want to create an instance.
If you have the library referenced, you don't need to go through the scripting library.
NOTE: This will only work in Visual Basic.
Dim fso As New FileSystemObject
I wanted to create a few macros for LibreOffice using BASIC. However I cannot find the API description. It is absent in help as well as in interet. When I try to google it I get masses of examples in C++, Java, Python, but not a single www with BASIC.
For example where from can I get the hierarchy of objects and their methods?
LibreOffice Basic uses essentially the same API as PyUNO and Java. That is, they all use the UNO API. To get started, the OpenOffice development guide helpfully describes the two main ways to step into the object hierarchy, the Global variables ThisComponent and, less commonly, StarDesktop. There also is a specialty variant in LO Base, ThisDatabaseDocument. To get the properties and methods of these objects, execute MsgBox oObject.DBG_properties or .DBG_methods. It often is easier to copy the longer lists that are returned by this method into a text editor for searching. You will find that all, or nearly all, of the methods and properties you reveal will be described in the LibreOffice UNO IDL API. The documentation for the API is not that descriptive, but you will be able to fill in some essential details using that resource Every Object has properties that can be reviewed by .DBG_properties.
The key properties for navigating the object hierarchy are .Parent, .Model, .CurrentController and occasionally .Source. The key methods are getByName() and getByIndex(). It also is helpful that events which trigger macros typically return an event object whose source or parent is the object that initiated the macro, for example, a command button. This object can be accessed by referring to it along with the Sub, i.e., Sub SubName (oEventObject As Variant)....
I am creating a COM library with Embarcadero C++ Builder. The designer for the ridl file gives several things you can add to the ridl. I think I understand all of them except for creating new "Modules". I can't find good information for it in the documentation.
What is a "Module" and what would it be used for in COM?
You say you can't find 'good information' in the documentation; what have you found? The RAD Studio help has a section specifically explaining modules, which says:
A module defines a group of functions,
typically a set of DLL entry points.
You define a module by
Specifying a DLL that it represents on the attributes page.
Adding methods and constants using the toolbar or the object list pane
context menu. For each method or
constant, you must then define its
attributes by selecting the it in the
object list pane and setting the
values on the Attributes page.
For module methods, you must assign a
name and DLL entry point using the
attributes page. Declare the
function's parameters and return type
using the parameters page.
For module constants, use the
Attributes page to specify a name,
type, and value.
Note: The Type Library Editor does not generate any declarations or
implementation related to a module.
The specified DLL must be created as a
separate project.
It seems it's specifying methods that exist in an external DLL to whatever module (EXE or DLL) the type library is built into. Exactly what that's used for... is a good question.
The module attribute is described in this MSDN Library page. It permits declaring entrypoints in a DLL. That has little to do with COM, it is just a capability of a type library. You'll find few language development environments that can use them. I think VB6 was one of them. Ymmv.
I've got a VSTO3 Word addin that makes use of custom ribbons and taskbars, etc.
Now, Office 2010 comes along and there's this nifty new BACKSTAGE concept, which I'd like to hook into. However, from what I can tell, doing it with VSTO requires Vsto 4, which requires VS2010, which isn't an option.
Soooo. I started looking online and have found all sorts of examples of, essentially, piggybacking the backstage XML onto whatever Ribbon xml I define and returning that as the value of GetCustomUI. All good, except if you're using VSTO3, there doesn't appear to be any way to "hook" into the call chain for GetCustomUI. It's all "automagically" handled for you by the OfficeRibbon and RibbonManage classes.
I know I +COULD+ convert the addin to a shared addin and just implement the IDTExtensibility interfaces directly. I'd lose all the vsto goodness (yeah, that's debatable) but I'd gain access to the GetCustomUI call.
Anyone every tried to get access to GetCustomUI +WHILE+ using VSTO though? Is it even possible?
I thought I could create a wrapper class for RibbonManager, but lo, MS has gone and done what looks to be some supreme violation of encapsulation. The RibbonManager implements the nice and easy IRibbonExtensibility interface, and yet, where that interface is passed around, they actually check the passed object to be sure it's of the actual type RibbonManager! Ugh, so much for any kind of wrapper.
Turns out it's possible, just not easy. You have to override the CreateRibbonExtensibilityObject method on connect, as well as the CreateRibbonObjects, and the RequestService methods.
Then, you have to create an object that wraps the built in VSTO RibbonManager object, and implements iReflect to intercept reflection INVOKE calls and forward them on to the underlying RibbonManager.
Finally, on the interceptor object, you have to also implement IRibbonExtensibility, then code up the GetCustomUI method of that interface.
once you do all that, your GetCustomUI will be called and passed in the full XML of the ribbons you've defined via VSTO, which you can then alter directly (in my case I needed to add backstage support), and then return that xml from the function.
definitely not straightforward, but it works.
If you want to edit XML ribbon at runtime in a VSTO app, I have created a simple solution here: Outlook 2007 ribbon customization in .NET using VS2010; insertBeforeMso dynamic function