Solved

C# COM Interop Server Property with Parameter

Posted on 2010-09-15
6
862 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 100 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in page 3 46
Not showing JavaScript in the list 5 40
Help with C#, MVC, razor. 6 23
Capture logon name 13 48
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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!
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.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now