title: How do I pass an excel range into a c++ function that expects a double ptr
body: <p>I am new to vba and excel programming, so excuse me if this is a stupid question.</p>
  
  <p>I have a c++ dll with a function </p>
  
  <pre><code>double foo(int n_bar, double* bar);
  </code></pre>
  
  <p>which I would like to call from excel using vba. I have declared the function in vba as</p>
  
  <pre><code>Declare Function foo Lib "mylib" (ByVal n_bar As Long, bar As Double) As Double
  </code></pre>
  
  <p>I have another wrapper function in vba that I will call from the spreadsheet</p>
  
  <pre><code>Function wrapper(a As Range) As Double
  </code></pre>
  
  <p>What does the body of the wrapper function have to look like to call the c++ function? My best guess was</p>
  
  <pre><code>Function wrapper(a As Range) As Double
      Dim retval As Double
      'after making sure there is only one column...
      retval = foo(a.Rows.Count, a.Cells(1,1))
  End Function
  </code></pre>
  
  <p>but that doesn't work (compiles and runs, but yields bogus results).</p>
  
  <p>Any help is appreciated</p>