locked
Simple COM question

    Question

  • We are converting VC++ COM component to VB.NET, gradualy. Our new VB.NET modules are called by the core VC++ program, so they need to be COM enabled until we convert the core module. We ran accros the following:

    An error class is defined and returned to the COM core when exception occurs. The error class is in VC++ DQSError.DLL:

        coclass DQSError {
            [default] interface IDQSError;
            ...
        };

    In the core module IDL, the IDQSError interface is "redefined" as it is the return value of many methods.

       interface IDQSEror : IDispatch {
        ....

    Our new VB.NET component, references the core COM module and implements one of its COM interface:

    <ComClass(...)> _
    Public Class MyClass
        Implements MyCore.IClientApp
    Public Function CoreFonc(...) as MyCore.IDQSError Implements MyCore.CoreFonc
    ...
    End Function

    However the real error class exists in the error module, so with option strict on, we canno return a DQSError class as a result of the call to CoreFonc, unless we DirectCast it

    Dim error1 as ErrorModule.DQSError = new ErrorModule.DQSError("error message") return DirectCast( error,  MCore.IDQSError)

    This double defininition ie IDQSError bugs us. Is anything wrong with what we do here ?
    Friday, February 24, 2012 2:24 PM

Answers

  • Hi Keboo,

    Welcome to the MSDN Forum.

    Based on my understanding, there is nothing wrong. 

    At first, please take a look at this article: http://msdn.microsoft.com/en-us/library/zcd4xwzs(v=vs.100).aspx 

    Restricts implicit data type conversions to only widening conversions, disallows late binding, and disallows implicit typing that results in an Objecttype. 

    And this one: http://support.microsoft.com/kb/311329 

    Option Strict restricts implicit data type conversions to only widening conversions. Widening conversions explicitly do not permit any data type conversions in which data loss may occur and any conversion between numeric types and strings. For more information about widening conversions, see the Widening Conversions section. 

    In your .net code, you have declared the return type is MyCore.IDQSError, based on the above articles, you can only return this type.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 27, 2012 7:51 AM

All replies

  • Hi Keboo,

    Welcome to the MSDN Forum.

    Based on my understanding, there is nothing wrong. 

    At first, please take a look at this article: http://msdn.microsoft.com/en-us/library/zcd4xwzs(v=vs.100).aspx 

    Restricts implicit data type conversions to only widening conversions, disallows late binding, and disallows implicit typing that results in an Objecttype. 

    And this one: http://support.microsoft.com/kb/311329 

    Option Strict restricts implicit data type conversions to only widening conversions. Widening conversions explicitly do not permit any data type conversions in which data loss may occur and any conversion between numeric types and strings. For more information about widening conversions, see the Widening Conversions section. 

    In your .net code, you have declared the return type is MyCore.IDQSError, based on the above articles, you can only return this type.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 27, 2012 7:51 AM
  • Hi Keboo,

    I didn't hear from you a couple of days.

    How about your issue now?

    Do you have any update?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 05, 2012 3:49 PM