• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Please help!

Joined
12/13/11
Messages
83
Points
18
Does anyone know how to pass an Excel range to a function written in a C++ dll?
 
crazymath, you can send it as one dimensional array of simple type (double or int). if you want to send matrix (2 dim array) just convert 2 dim into 1 dim and convert back in C++ code. If I remember right you may find this approach in Dalton book I gave you link to last time.
 
C++:
Vector<DOUBLE> ExcelUtils::ExcelRangeToVector(Excel::RangePtr pRange)
{
    // Get the number of rows and columns in the range
    int columns=pRange->Columns->Count;
    int rows=pRange->Rows->Count;
 
    // Create the vector with the correct size
    Vector<DOUBLE> v(columns*rows);
 
    // Iterate the rows and columns
    int index=v.MinIndex();
    for (int r=1; r<=rows; r++)
    {
        for (int c=1; c<=columns; c++)
        {
            // Add each element in the range to our vector
            v[index++]=(((Excel::RangePtr)pRange->Item[r][c])->Value).dblVal;
        }
    }
 
    // Return the vector
    return v;
}
You can use the Excel Object Model
 
Back
Top