What is the COM object of javascript
COM object refers to "Component Object Model Object", which is a reusable software component that uses COM specifications; using COM specifications can ensure that COM objects work well and can be easily integrated into your in the application. COM objects are generally implemented using dynamic link libraries (DLLs); like ordinary DLLs, COM objects expose some methods that the user's application can call to complete any supported operations.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
What is a COM object?
A Component Object Model (COM) object is a reusable software component that uses COM specifications. Using COM specifications ensures that COM objects work well and are easily integrated into your applications. In fact, COM is basically equivalent to a black box, which can do a lot of work for your application.
COM objects are generally implemented using dynamic link libraries (DLL). Like ordinary DLLs, COM objects expose methods that your application can call to complete any supported operation. The interaction between applications and COM objects is somewhat like the interaction between applications and C objects, but there are some significant differences between them.
COM objects implement precise encapsulation. You can't simply create an object and call its public methods arbitrarily. A COM object's public methods are put into one or more interface groups. For the use of methods, you must create a COM object and obtain an appropriate interface for the COM object from the COM object. For example: The IDirect3DCubeTexture8 interface contains a method that allows you to handle cube frame resources. Any methods that do not belong to this interface are inaccessible.
The creation of COM objects is different from the creation of C objects. There are several ways to create COM objects, but all involve COM-specific technologies. Microsoft's DirectX application programming interface (API) contains a variety of helper functions and methods for creating most DirectX objects.
You must use COM_specific techniques to control the lifetime of COM objects.
COM objects do not need to be explicitly loaded. COM objects are contained in a DLL. However, when you use this COM object, there is no need to explicitly load the DLL or explicitly load the static library. Each COM object has a unique registration ID used to create the object. COM will automatically load the correct DLL.
COM is a binary specification. COM objects can be written to and accessed from a variety of languages. You don't need to know anything about the COM object source code. For example: Microsoft Visual Bisice applications routinely use COM objects to write C.
##Objects and interfaces
- ▲A COM object can expose any number of interfaces. For example: all COM objects must expose the IUnknown interface, and they generally expose at least one additional interface, and possibly more. In order to use these special methods, you not only have to create the COM object, but also get the correct interface pointer.
- ▲Many objects may expose the same interface. An interface is a set of methods that perform specified operations. The definition of an interface specifies the syntax of methods and their functionality. Any COM object that supports special operations exposes an appropriate interface. Some interfaces are highly specialized, and they are only exposed by a single object. In most other cases it is exposed by multiple objects. A very special case is that the IUnknown interface must be exposed by every COM object.
It is very common for an interface to have several generations. Often, their substance is the same, but their details are different. Typically, an object can expose each generation of interfaces. Doing so allows older programs to continue to use the object's older interface, and newer programs to take advantage of the new interface's features. Usually, interface families have the same name, followed by an integer indicating the generation. For example: If the original interface is named IMyInterface, then the next two generations of interfaces are named IMyInterface2 and IMyInterface3. Integers generally use the version number of directx.
GUIDS
Globally Unique Identifiers (GUIDS) are a key part of the COM program model. At its most basic principles, GUIDS is a 128-bit structure. However, GUIDS are created in a way that ensures that no two GUIDS are identical. COM extensively uses GUIDS for two main purposes:
1. To uniquely identify a specific COM object.
2. To uniquely identify a specific COM interface.
Return value (HRESULT)
All COM methods return a 32-bit value named HRESULT. For most methods, the HRESULT is actually a structure containing two pieces of information.
1. Whether this method succeeds or fails.
2. Output detailed information about the operations supported by the method.
The HRESULT value returned by some methods is defined in Winerror.h. The HRESULT value returned by the method can also be some user-specific information. These values are usually verified in the method's reference page.
The fact that method calls on COM objects can return a variety of codes indicating success or failure of the call means that you must be very careful to test its return value. For example: If the return value of a method call is
S_OK, this indicates that the method call was successful. If the return value is S_FAIL, it indicates that the call failed. Of course, the method call may also return other codes indicating the success or failure of the call. The following code snippet illustrates that it is unsafe to perform such a simple test on the code. The value of hr in the code is the return value of the method call:
if( hr == E_FAIL ) { //Handle the failure } else { //Handle the success }
If this code only returns E_FAIL, this code snippet can work well. However, this is not the case. This method call may also return other values, such as: E_NOTIMPL, E_INVALIDARG. If the code returns these values, this code segment does not process them, and by default it will indicate that the program is executing normally, but the actual program does not Incorrect.
If you want to know more detailed information about a method call, you must test each relevant return value. However, you may just want to know whether the method call was successful. A good way for you to test whether a method call is successful is to pass the method's return value to the following two macros, which are defined in the winerror.h file.
1. The macro SUCCEEDED returns TRUE to indicate that the call is successful, and returns FALSE to indicate that the call failed.
2. The macro FAILED returns TRUE to indicate that the call failed, and returns FALSE to indicate that the call was successful.
You can use the FAILED macro to modify the previous code segment.
if( FAILED(hr) ) { //Handle the failure. } else { //Handle the success. }
The above code snippet handles E_NOTIMPL and E_INVALIDARG errors.
Although the return value HRESULT of most methods is a structure value, the return value HRESULT of a few methods is a simple integer value. This implies that methods that return integer values can always be called successfully. If you pass a return value of this type to the SUCCESS macro, the macro will always return TRUE. A common example is the IUnkoown::Release method. The function of this method is to release (decrement) the usage count of an object and return the object's current usage count. The usage count is used to identify the lifetime of an object.
The address of the pointer
If you have seen some reference pages for COM methods, you may have encountered some like the following Situation:
HRESULT CreateDevice( . . . IDirect3DDevice8 **ppReturnedDeviceInterface )
Generally, any C or C developer is familiar with pointers, and COM usually uses an additional indirection standard. The standard is: two asterisks (**) followed by a type specification and the variable name with the typical "pp" prefix. In the previous example, the ppReturnedDeviceInterface parameter is the address of a pointer to the IDirect3DDevice8 interface.
Unlike c, you cannot directly access the methods of a COM object. Instead, you must obtain a pointer to an interface that exposes the methods. The syntax for calling methods of an object interface is the same as the syntax for calling C methods using pointers. For example: to call the IMyTnterface::DoSomething method, you only need to use the following syntax.
IMyInterfance *pMyTface; . . . pMyIface->DoSomething(...) ;
For pointers to COM object interfaces, you cannot directly create a pointer to the interface. You must call one or more other methods to obtain this pointer. For example: the CreateDevice method mentioned earlier.
To get the interface pointer through this method, you need to declare a variable to point to the interface you requested. Pass the address of this variable to the CreateDevice method. In other words, you must pass the address of a variable to this method. When this method returns, this variable will point to the interface you requested, and you can access the methods of this interface through this pointer.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of What is the COM object of javascript. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service
