Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Data passing from DLL to Excel

Posted on 2000-04-23
2
Medium Priority
?
213 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 40 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

971 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