How does COM support advanced parameters?

But how does COM support them? Does C ++ support them? Don't I know that all COM codes are written in C ++? Or is COM just a methodology, a way to build your application?

I am curious. I've been writing a lot of COM automation from C # lately and this question just came to me.

+2


source to share


2 answers


this link can help answer your question about optional parameters (the answer is yes you can do): http://msdn.microsoft.com/en-us/library/f25e2b6b%28VS.80%29.aspx

com is a binary specification. you can technically create a COM object (server) in any language. Microsoft languages ​​are clearly (ominously?) Making it easier than others because they wrote the specification. you can create a com-server in direct C ... technically. in fact, this is a large-scale event.



Best wishes don

+3


source


If you are working with COM and Automation in C / C ++ (or older versions of Delphi), you should use VARIANT for the parameters you want to make optional. Also, optional arguments defined in C ++ style are not supported for COM.

However, for those VARIANTs that you have to provide when you call another object and you want to specify additional parameters (for example, when talking to MS Word or Excel via Automation), you will need to initialize these OPTIONS with the VT_ERROR type and the field scode set to DISP_E_PARAMNOTFOUND.

When accepting calls from other objects that might be missing parameters (VBScript, JScript), you need to check all your VARIANTs for cases where the type was set to VT_ERROR and the scode field was DISP_E_PARAMNOTFOUND.

... .NET Equivalent - Use the object set to Type.Missing for those parameters mapped to optional COM parameters. The following link can be helpful for viewing both sides of the story.

... NET4Office: Type.Missing, C # and Word (MSDN Blog)



This is all due to the way older versions of VB (6 and earlier) handled optional arguments. Here is the MS support KB link which is pretty concise.

How to pass optional parameters when calling a function from C ++ (kb238981)

To address other issues, it is incorrect to assume that most COM objects are written in C ++, because COM is strict about declaring interfaces and interface layouts in a known way. It doesn't matter what language or tools are used to create COM objects as long as they observe and obey the mockups of the supported interfaces.

Finally, you are correct that COM is a methodology - not really in the sense of customizing the architecture for any particular application, but in making it possible to clearly define the interrelated components that can make up an application or can be accessed by other applications.

+3


source







All Articles