Solved

C# COM Interop Server Property with Parameter

Posted on 2010-09-15
6
876 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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