Solved

C# COM Interop Server Property with Parameter

Posted on 2010-09-15
6
857 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:TerryDean
Comment Utility
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
Comment Utility
Can you show me your VB.NET code (if you have some to share)?
0
 

Accepted Solution

by:
TerryDean earned 0 total points
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

16 Experts available now in Live!

Get 1:1 Help Now