The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Direct to COM compiler

I'd like to know how to do this.

Poking around the web seems to reveal a distinct lack of options. C++, VB (pre-.Net) and Delphi, plus the no-longer-to-be-found Oberon. Is it truly that painful to implement? I know you can write COM in plain old C, and even if you write in C++ you can still emit assembly as an intermediate to investigate what is going on under the hood.
Aaron F Stanton Send private email
Tuesday, August 28, 2007
It's been pointed out to me that there are open source scripting languages that hook into COM pretty easily, so I'll look into those as well.
Aaron F Stanton Send private email
Tuesday, August 28, 2007
.Net has COM interop.

And you can develop COM components in VBScript or Javascript.
Yury @ Xtransform Send private email
Tuesday, August 28, 2007
I guess I don't understand what you are saying. You appear to be saying that none of the new languages seem to care to support COM. Are you that surprised? COM is a mess and I'm personally very glad to see that it is dying (although it is dying a rather slow death).

"Is it truly that painful to implement?"

No it's not. .NET supports COM interop going both ways. But very few people who use .NET want to use it to create COM components. Why would they want to do that anyway? So stick with C/C++, VB6, or Delphi if you still want to create COM components. But be aware that COM is considered to be a legacy technology by many people. It's not that it is difficult to support. It's that there is really no reason to support it when better options are available.
Tuesday, August 28, 2007
Sorry, I guess my vague rambling wasn't clear.

I don't want to create COM components.  I want to learn how to write a compiler that creates COM components directly, much as VB6 and Delphi do.
Aaron F Stanton Send private email
Tuesday, August 28, 2007
> I want to learn how to write a compiler that creates COM components directly, much as VB6 and Delphi do.

I'm guessing you already know how to write a compiler, and what you want to know is how to create and call COM components.

I found that _Essential COM_ by Don Box was enough to get me writing and using COM components, using C++ and nothing else (e.g. without .NET, MFC, or ATL): so I think you'd find that book a sufficient explanation of how COM is implemented at the machine level, if you understand how C++ equates to machine code.
Christopher Wells Send private email
Tuesday, August 28, 2007
Don't we already have lots of compilers that create COM? Is there a reason why you are reinventing the wheel?
dood mcdoogle
Tuesday, August 28, 2007
I'm going to go out on a limb and guess that dood didn't bother to read my first post nor to do any thinking/research before posting his answer, nor understands the value of learning how to do things as an intellectual exercise.

There may be "plenty" of languages out there already, but few compile direct to COM, and none that do it that I have found have the source of the compiler itself available to study.  As far as "why reinvent the wheel" goes - with that kind of logic, why send kids to school at all?  After all, they're not doing anything new.

I want to *learn*.
Aaron F Stanton Send private email
Wednesday, August 29, 2007
I read your first post but it doesn't say anything about wanting to "learn". It read more like you were looking to create COM components and not create a compiler. I see that you mentioned as such later so I apologize for not understanding your ramblings.

I understand the value of learning but am always amazed at how many people want to write "compilers" to learn something. You will probably end up like most people who set out down this path and spend about 20 hours before deciding it just isn't worth it. There are a lot of ways to learn how to do things. Writing a compiler is seldom the best way to learn something unless the thing that you want to learn is how to write a compiler.

But best of luck anyway.
dood mcdoogle
Wednesday, August 29, 2007
I have to agree with dood. The problem with writing a compiler that will output X as a means to learn X is that you actually need to know X before you can start work on the compiler.

While it may seem like a cool project, as a learning exercise you've got it the wrong way around.
Wednesday, August 29, 2007
"...unless the thing that you want to learn is how to write a compiler."

It is.  Specifically, a compiler that directly emits COM components.
Aaron F Stanton Send private email
Wednesday, August 29, 2007
Can you please explain what "a compiler that directly emits COM components" is?? Maybe point to an example or put at least a modicum of effort in explain what it is you're after... because I don't get much from what you've said so far.

COM is a binary protocol... which I guess has a lot to do with compilation. However, there is also the registration of the COM object part that really doesn't have much to do with the compiler. I'm just confused with what you are trying to accomplish.
Captain Confused
Saturday, September 01, 2007
Actually, you can do COM without registration, using side-by-side assemblies, but my primary interest is in following the binary standard.  COM also has a certain amount of overhead, like interfaces should derive from IUnknown, and it would be useful to include default implementations of the required functions.  Additionally, it would be handy to include the necessary parts to make dual interfaces work.  Last (or near last) would be embedding the binary type libraries as resources in the compiled executable.  All this is done transparently by VB6, as a concrete example, with no effort required on the part of the person using the compiler.

Given .Net's omnipresence, it would also be useful to create primary interop assemblies by default, too.

Anyway, to make the binaries useful via Automation (and .Net) would mean creating and consuming COM types, I suppose.

Does that help?
Aaron F Stanton Send private email
Tuesday, September 04, 2007
I'd recommend "Inside COM" as a gentle introduction to COM, and Don Box if you enjoy torturing yourself - jk.

If you want to make your components usable as COM components, you need to do a few things:
0) Give the component a name - a CLSID
1) Advertise them in the registry
2) Client will look up for the CLSID and find the name of the dll where it is implemented (InprocServer32)
3) Write that DLL and export a method called DllGetClassObject
4) Write code in the DllGetClassObject that eventually returns a VTABLE for the requested component.
5) Implement the VTABLE yourself, that knows how to forward method calls to your component
6) Marshal input arguments on the way in and return arguments on the way out

This, and a few details along th way:)
Sunday, September 16, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz