?
Solved

C# COM Interop Server Property with Parameter

Posted on 2010-09-15
6
Medium Priority
?
894 Views
Last Modified: 2013-12-16
Hi,

I am attempting to migrate an existing COM component to dotnet and need to keep the new code binary compatible with the old component.  One of the classes in the existing component's IDL has a number of properties that have an optional parameter.  Here is an extract for the class:

interface _IComponent : IDispatch {
        [id(0x80013001), propget]
        HRESULT Info([out, retval] _IComponentInfo** retval);
        [id(0x80013002), propget]
        HRESULT Value(
                        [in, optional] VARIANT Row, 
                        [out, retval] BSTR* retval);
        [id(0x80013002), propput]
        HRESULT Value(
                        [in, optional] VARIANT Row, 
                        [in] BSTR retval);
        [id(0x80013003), propget]
        HRESULT Status(
                        [in, optional] VARIANT Row, 
                        [out, retval] short* retval);
        [id(0x80013003), propput]
        HRESULT Status(
                        [in, optional] VARIANT Row, 
                        [in] short retval);
        [id(00000000), propget]
        HRESULT _Value(
                        [in, optional] VARIANT Row, 
                        [out, retval] BSTR* retval);
        [id(00000000), propput]
        HRESULT _Value(
                        [in, optional] VARIANT Row, 
                        [in] BSTR retval);
    };

Open in new window


How can I replicate this code in C# since there does not seem to be the ability to use a parameter with a property.  The second question is how to have an optional parameter ( [in, optional] VARIANT Row) defined before a required parameter ([in] BSTR retval)?

Thanks for your help!
0
Comment
Question by:TerryDean
  • 3
  • 3
6 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 400 total points
ID: 33690880
If you have 2010, you can handle optional arguments with dynamics.  If you don't have that version, then you don't have that capability.
0
 

Author Comment

by:TerryDean
ID: 33695961
Thanks for the information, but I don't see how dynamics will help with creating a COM server.  Can you please explain.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33696045
1) I am not sure if you can duplicate

2) Dynamics is the concept for late-binding, run-time evaluation

3) 2010 can handle optional parameters, but before 2010, C# couldn't handle optional parameters.

4) You can register a .NET assembly as a COM component
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:TerryDean
ID: 33718516
Thanks again for the information but unfortunately it doesn't contribute to solving the problem.  The only way to do this in .NET that I have been able to determine is to switch to visual basic.  Any other suggestions?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 33719018
Can you show me your VB.NET code (if you have some to share)?
0
 

Accepted Solution

by:
TerryDean earned 0 total points
ID: 33782862
Hi,

It took some time as this is only one of the classes of a component that has 60 classes.  Here is the interface:

Public Interface _IComponent
        <DispId(CInt(0))> _
        Property _Value(Optional ByVal Row As Object = Nothing) As String

        <DispId(CInt(&H80013002))> _
        Property Value(Optional ByVal Row As Object = Nothing) As String

        <DispId(CInt(&H80013003))> _
        Property Status(Optional ByVal Row As Object = Nothing) As Short

        <DispId(CInt(&H80013001))> _
        ReadOnly Property Info() As ComponentInfo

    End Interface

Seems to work fine so far.  Thanks for your help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question