Solved

C# COM Interop Server Property with Parameter

Posted on 2010-09-15
6
869 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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