none
Interop with different versions of a COM object RRS feed

  • Question

  • Hello, I'm writing a small app that needs to be interfaced with Microsoft Fax Services to send faxes.

    I'm using Microsoft Fax Service Extended COM Type Library and everything works fine since I move to another OS version. That is, if I compile my app with Windows XP the app works well if deployed on Windows Server 2003 too but, if I deploy it on Windows Server 2003 R2, 2008, 7 etc the app does not work. This is because the Microsoft Fax Service library exposes different behaviour.

    I'm asking you this: how can I create a managed library that shields my application from different Microsoft Fax Service Extended COM Type Library versions? How can I create it in a way that works with every OS? Do I have to create an interop on each os I'd like to support?

    I'd like to have an hint on how to approach the problem.

    best regards

    Alessandro

    Monday, April 19, 2010 10:09 AM

Answers

  • It depends on the type of changes in the COM server. If the definition of interfaces have changed (which is IMO unlikely), then you might need multiple interop assemblies.
    My bet is that just some behavior of the COM server has changed - find out what exactly it is and then decide what to do. For example: The new behavior might work also on down-level OS - in such case a fix to your application might solve your problems.

    -Karel

    • Marked as answer by eryang Tuesday, June 29, 2010 3:28 AM
    Monday, April 19, 2010 4:06 PM
    Moderator
  • The general solution to this is that I've used is to use the late-binding "scripting" interfaces.  It's not much fun at development time because you don't get IntelliSense etc, but you don't add references to Dlls or anything. You do what scripts do, except that you use C# code.  Scripts that send email using Outlook have never needed interop Dlls, right? Same with the Fax service.

    http://sandlerco.com/VBScript.htm 


    Phil Wilson
    • Marked as answer by eryang Tuesday, June 29, 2010 3:28 AM
    Monday, April 19, 2010 10:12 PM

All replies

  • It depends on the type of changes in the COM server. If the definition of interfaces have changed (which is IMO unlikely), then you might need multiple interop assemblies.
    My bet is that just some behavior of the COM server has changed - find out what exactly it is and then decide what to do. For example: The new behavior might work also on down-level OS - in such case a fix to your application might solve your problems.

    -Karel

    • Marked as answer by eryang Tuesday, June 29, 2010 3:28 AM
    Monday, April 19, 2010 4:06 PM
    Moderator
  • The general solution to this is that I've used is to use the late-binding "scripting" interfaces.  It's not much fun at development time because you don't get IntelliSense etc, but you don't add references to Dlls or anything. You do what scripts do, except that you use C# code.  Scripts that send email using Outlook have never needed interop Dlls, right? Same with the Fax service.

    http://sandlerco.com/VBScript.htm 


    Phil Wilson
    • Marked as answer by eryang Tuesday, June 29, 2010 3:28 AM
    Monday, April 19, 2010 10:12 PM
  • Hi Alessandro,

    I'm writing to check the issue status, does above suggestions help?


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, April 22, 2010 6:04 AM
  • I'would prefer not to use scripting. Instead I'd like to use the dynamic type introduced with the .Net Framework 4.0 and the new interop functions.

    Can anyone help me on this matter?

    Best regards

    Alessandro

    Friday, April 23, 2010 2:59 PM
  •  

    With the support of DLR, it is easier to write dynamic code in your .NET application, for this case, you may use code like this:

     

                dynamic faxServer = GetFaxServer();

                faxServer.Connect();

     

                if (Environment.OSVersion.VersionString == Windows2003)

                {

                    dynamic faxDoc = CreateFaxDocForWin2003();

                    // Some steps for Windows 2008.

                    faxServer.SendFax();

                }

                if (Environment.OSVersion.VersionString == WindowsServer2008)

                {

                    dynamic faxDoc = CreateFaxDocForWin2008();

                    // Some steps for Windows 2008.

                    faxServer.SendFax();

                }

     

    See also:

    Walkthrough: Creating and Using Dynamic Objects (C# and Visual Basic)


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, April 26, 2010 2:54 AM
  • Hi Alessandro,

    How about the issue status?


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 3, 2010 5:59 AM