1

I'm trying to understand COM concept. As per my understanding: COM is a binary interface or executed function library (in machine language) which could be extended or re-used by any programming languages with the help of its functions and property exposed by the vendor.

SO in case of below code could we say Fso or Txtobj object created is a COM or ActiveX object?

And if we want to create the same file system or Text stream object in other programming languages like Java, what should we do? Since we say COM as language independent.

Set Fso = CreateObject("Scripting.FileSystemObject")

Set Txtobj = Fso.CreateTextFile("C:\Users\ACER\Desktop\Project Folder\NewText_5.txt")
3
  • You can't be told how to do com for any language as each language does com support differently.. If you just want to know how to do com for java, please clarify (and add the java tag to your question) and you will get much better answers to your question. Commented Feb 23, 2013 at 18:49
  • Than you. My question had two parts: Commented Feb 23, 2013 at 18:57
  • Than you. My main part of the question is: on what basis do we call an object as a COM Object? And second one is how language independence is achieved in the above case where microsoft has given the file system object model with functions and properties. I'm sorry if my question still sounds vague. Commented Feb 23, 2013 at 19:07

1 Answer 1

4

If I understand correctly what your questions are:

Something is a COM object based on how it is built to expose its functionality to other code that uses it. It must be built to follow certain rules and it has to provide certain functionality that is mandatory, and it must do so in a very specific way at the binary level (bits and bytes). Unfortunately, the specific rules are lengthy and too complex to explain in this answer.

There are also rules and specific binary requirements that must be obeyed by the code that uses the object.

The language independence comes from the fact that the rules are so precise and that they are designed so they are not tied to any specific language. Many languages can be used to write COM objects, and many languages can use COM objects. By which I mean that those language need to provide a mechanism for the programmer to obey those rules. That is key: the rules don't specific how the language should make it possible to obey the rules. Each language has different ways; some languages will automatically take care of a lot of details for you while others require you to do most of the work by hand. some use a special syntax just for COM, while others use the same syntax they use for everything else.

Note that "language independence" (I would call it more appropriately "language neutrality") is not the same as "language universality". Not every language can use COM.

With that in mind, your answers are:

1) How do you know if something is a COM object from reading a line of code such as those in your example?

The true answer is: "it depends on how the object was written. If it's written to obey the rules of COM and it's called via COM mechanisms in your language, then it is a COM object". In the specific case of looking at code and trying to decide if it's COM without looking at the details of the object, the answer is: "It depends on the language."

In your example code in VBScript, both are COM objects. The fact that the expression uses the Set command tells you immediately that the variables will refer to a COM object. Remember, the answer will be different in other languages (for example, even in VB6 the presence of set is not enough to know if the object is a COM object).

2) How is the language independence achieved?

It is achieved by the use of strict rules at the binary level. Different languages comply with the rules different ways and that is OK. Some languages cannot comply with those rules, and they so not support COM.

Those specific objects you show have their own functionality and yes, they work through functions and properties; those are some of the rules. If a language doesn't have a mechanism that allows you to call those functions, then that language cannot be used to use COM objects.

If you want to learn the rules, they are usually expressed in C or C++, and one of the best books on the subject is "Essential COM" by Don Box.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.