C++ and Office (Excel) development

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Y2lt?=

    #1

    C++ and Office (Excel) development

    Hello everyone,
    I would like to be able to write generic (i.e. non-managed) C++ code which I
    could use in a library with Excel as the front end. I would like to be able
    to maintain a code base that will compile in a non-windows environment. Can
    anybody provide any pointers on how to do that? Can anybody provide any clues
    as to how that code can be wrapped for use with Excel? Or is COM (or managed
    code) the only way to go?

    Thanks in advance,
    Constantinos

  • Giovanni Dicanio

    #2
    Re: C++ and Office (Excel) development


    "cim" <cim@discussion s.microsoft.com ha scritto nel messaggio
    news:09596B69-0D21-435B-9CB1-A042424E73F8@mi crosoft.com...
    I would like to be able to write generic (i.e. non-managed) C++ code which
    I
    could use in a library with Excel as the front end. I would like to be
    able
    to maintain a code base that will compile in a non-windows environment.
    For the non-windows environments, you can use multiplatform and standard
    libraries, like STL.
    For example, if you want to store an array of data, you have several
    options: you could use CAtlArray (from ATL), but it is Windows-specific.
    Another option is to use std::vector from STL, which will compile fine also
    on non-Windows platforms.

    You can design your code separating the multiplatform part (written in
    standard C++, using standard and multiplatform libraries like STL), from the
    Windows-specific part.
    The Windows-specific part should use COM to export the multiplatform "core"
    part towards Excel.
    Excel (and Office in general) are heavy based on COM technology, so I think
    that COM is the way to go if you want to extend Excel from native C++.

    A possible architecture could be like the following:

    - core part (standard C++, STL)
    - COM objects wrapping the "core" (built with C++ with ATL)
    - VBA code in Excel that calls the COM objects

    There is also another option to built Excel add-ins, using XLL technique
    that does not require COM.
    It is explained a bit here:



    However, I think that it is a legacy technology, and I would definitely
    suggest using COM for that job.

    Giovanni


    Comment

    • =?Utf-8?B?Y2lt?=

      #3
      Re: C++ and Office (Excel) development

      Thanks for the answer Giovanni.

      The problem I have is with the design and implementation of the wrappers.
      First of all every single class would have to be wraopped. Second, what
      happens with inheritance? Do you wrap both the parent and the child for a
      class? And how about virtual methods for these classes? It seems to me that
      this becomes a mess fast.

      C.




      Comment

      • Giovanni Dicanio

        #4
        Re: C++ and Office (Excel) development


        "cim" <cim@discussion s.microsoft.com ha scritto nel messaggio
        news:7F42D74A-5C17-472E-9018-59CFF9079828@mi crosoft.com...
        Thanks for the answer Giovanni.
        You are welcome.
        The problem I have is with the design and implementation of the wrappers.
        First of all every single class would have to be wraopped. Second, what
        happens with inheritance? Do you wrap both the parent and the child for a
        class? And how about virtual methods for these classes?
        You can have a system made up by several objects (classes), but it can
        happen than only a small subset of them needs to be exposed to Excel via COM
        (the other classes are part of the core system, but they are not required to
        be exposed in the interface part).
        So you can just build COM objects to wrap this subset.

        I don't know other options different than COM to expose an object model
        using native code and C++ (if we exclude the primitive XLL technique I
        posted in the other message).

        Giovanni


        Comment

        Working...