Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:05:11+00:00 2026-06-01T04:05:11+00:00

I am converting a MFC C++ COM Addin to a VSTO Excel Addin in

  • 0

I am converting a MFC C++ COM Addin to a VSTO Excel Addin in
C# .NET4.0. There is a lot of code referring to the C API in it.
Here is an example. I am possibly going to use Excel DNA to simplify my
conversion task.

FYI: xlr is a class in the XLSDK.

//allocate local storage for the reference
m_pControllerReference = new xlr( controllerRange ) ;

//get the name of the book and sheet with the reference
   g->Excel.fn( xlSheetNm, *m_pControllerReference ) ; 

   if ( g->Excel.resultXltype() != xltypeErr )
   {
       m_referenceSheetName = g->Excel.resultCString() ;

//    and get the sheet ID
       g->Excel.fn( xlSheetId, xl(m_referenceSheetName) ) ; 

       if ( g->Excel.resultXltype() != xltypeErr )
       {
           m_controllerSheetId = g->Excel.resultSheetId() ;

           xlr theRange( m_pControllerReference->GetLPXLOPER(),
0, TRUE ) ;

           if(theRange.nRows() >6)

           ........etc

Does this convert like this?

          m_pControllerReference = (Excel.Range)controllerRange;

          m_referenceSheetName =
(string)XlCall.Excel(XlCall.xlSheetNm, m_pControllerReference );

          m_controllerSheetId =  XlCall.Excel(XlCall.xlSheetId,
m_referenceSheetName);    // and get the sheet ID

          //how to convert this ?
          //xlr theRange( m_pControllerReference->GetLPXLOPER(),
0, TRUE ) ;

Or is there a better way of converting without resorting to a 3rd party utility? Can I do everything in VSTO? Is there a chart somewhere of C API to C# conversions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:05:12+00:00Added an answer on June 1, 2026 at 4:05 am

    Excel-DNA should indeed make your Excel C++ to .NET conversion much easier.

    You should be careful of trying to mix VSTO and Excel-DNA. They don’t live together happily in the same add-in, so you should either base everything on Excel-DNA (which allows you to access both the C API and the COM interfaces), or make two separate add-ins (VSTO has some ribbon and other high-level wrappers which can be convenient.)

    To access the C API from Excel-DNA you use the XlCall class as you have noticed, together with the ExcelReference class, which contains the information from a reference type XLOPER. With Excel-DNA you never have to deal with XLOPERs explicitly, all type conversions are automatically done when you make the XlCall.Excel(…) call.

    You should not confuse the C API helper type ExcelReference, with the COM type Range. You can convert back-and forth, but they are not interchangeable. For C API calls you need the ExcelReference type.

    Turning to your example, it’s not clear what controllerRange is, but I’d guess type xlr type is the equivalent of Excel-DNA’s ExcelReference type, rather then the COM Range type you are using (as Excel.Range). Here is a post about converting between ExcelReference and Range: http://groups.google.com/group/exceldna/browse_frm/thread/7a16e20e9067d3d2.

    When you have an ExcelReference, your calls are correct. So this should work:

      m_pControllerReference = new ExcelReference(0,0,0,0, "Sheet1"); // Cell A1
      m_referenceSheetName = (string)XlCall.Excel(XlCall.xlSheetNm, m_pControllerReference ); 
      m_controllerSheetId =  XlCall.Excel(XlCall.xlSheetId, m_referenceSheetName);
      // or just: 
      m_controllerSheetId =  m_pControllerReference.SheetId;
    

    Now I’m not sure what your last line does – it seems to create another xlr object.
    The ExcelReference has properties RowFirst, RowLast that you’d use to check how many rows it has.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got several large MFC applications here, and converting them into any other format
Converting the hour seems to take a lot of work... there must be a
Converting my current code project to TDD, I've noticed something. class Foo { public
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
#define __T(x) L ## x Found in code from one of the MFC source
converting some CSS to Sass, for example: .ptn, .pvn, .pan{padding-top:0px !important} to this @mixin
converting a WSDL to a REST web service, Is there a C# version of
Just converting some shell scripts into batch files and there is one thing I
I am converting some Objective-C++ code into plain Objective-C and I am having some
In my MFC application I am reading Japanese characters from string table then converting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.