Solved

Data passing from DLL to Excel

Posted on 2000-04-23
2
203 Views
Last Modified: 2010-04-02
Hi,

I deadly need your help.

What I am trying to do is to call a DLL and get some data under Excel 97. The input data from Excel to the DLL is real-time data, and I need to get back 5 "double" variables calculated by the DLL written by C++. In Excel, I can call the DLL 5 times in 5 different cells to get all of them, but each call will repeat the same calculation. Due to the HEAVE computation, five calls are very slow. These five data is calculated from the same single computation procedure, so I want to put them in an array and have the array passed back to Excel by one call. Under Excel, the data type code for the arry is "K", and the array should be decalred as FP in the DLL(Detail of this can be found at http://msdn.microsoft.com/library/officedev/office97/SEC7C.htm). I tried to work it out, but failed. There is no sample codes from Microsoft, and I could not find any help from its Excel 97 developer's kit book.

Please give me some helps. If possible, please post your source codes.

Many thanks.
0
Comment
Question by:jasonwan
2 Comments
 
LVL 4

Accepted Solution

by:
wylliker earned 10 total points
ID: 2742900
Why not modify your DLL ...
Instead of calculating everytime you call into the DLL add another parameter.

Sort of like ...

double  GetValue(unsigned short Index, unsigned short fRecalculate)

In Excel just call the function for each value (the index parameter could be the index into an array in your DLL)and only pass the recalculate flag as 1 (true) on the first call (and subsequently on the first call the next time you need updated data) and as 0 (false) for the other 4 calls.  

This way you avoid having to get into passing any arrays and the overhead to support this.

For example:

  GetValue(0, 1)
  GetValue(1, 0)
  GetValue(2, 0)
  GetValue(3, 0)
  GetValue(4, 0)

Only on the first call would you calculate all of the doubles into an array.

In your GetValue function you would have ...

  double GetValue(unsigned short Index, unsigned short fRecalculate)
{
  if(fRecalculate)
  {
     Calculate() // whatever you may need to do this
  }

  if(Index < MAX_INDEX)
     return Array[Index];
}


Something like what I have described ought to work for you








0
 
LVL 3

Expert Comment

by:altena
ID: 2743202
wylliker: Thats an answer. Looks good enough to me.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now