SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
tbonds
Topic Author
Posts: 246
Joined: July 14th, 2002, 3:00 am

Trouble with Steve Dalton's Excel/C++ Book Example

July 9th, 2005, 10:16 pm

Hi Group.I just got the Dalton book on Excel/C++ Add-In Development and am having problems with the example on page 83.Has anyone gotten the Get_System_Time_C function to work as the example in the book claims it does? It's just a simple function that calculates and returns the system time, created as a DLL, and called using VBA in Excel.First of all, book has lower case for the EXPORTS delclaration in the projects .Def file, which was the first error that screwed me up as C++ is obviously case-sensitive.However, not that that's fixed, I get a problem with the numbers being returned from the DLL to the VBA function.Instead of getting a date/time like "38542.7932797454", the Get_System_Time_C function is only returning the deciminal portion, i.e. "0.7932797454". The VBA function takes and returns a double so I should be OK. Does that mean the DLL or the original code is wrong?Anyone know what might be causing this. I'm just starting to learn VC++ 6, although I have VBA experience. I'm simply cutting/pasting the code provided by the author on the CD ROM to get a feel for the process of creating DLLs and was not expecting so much trouble with what I thought was an easy example. Before I start running major debug tests I thought somone might have come across the same thing, either with this book or from their own experiences.TIA (See code for .cpp and .def files below. Replace smiley faces with semicolon and right parenthesis). -------------------------------------------------------------------------------------------------------------------------------------//============================================================================//============================================================================//////============================================================================//============================================================================// This source file contains code relating to getting the system time and// system clock.//============================================================================//============================================================================#include <time.h>#define SECS_PER_DAY (24 * 60 * 60)// CLOCKS_PER_SEC defined in <time.h>#define CLOCKS_PER_100TH_SEC (CLOCKS_PER_SEC / 100)//==========================================================================// Returns the time of day rounded down to the nearest second as number of// seconds since the start of day.//==========================================================================long current_system_time(void){ time_t time_t_T; struct tm tm_T; time(&time_t_T); tm_T = *localtime(&time_t_T); return tm_T.tm_sec + 60 * (tm_T.tm_min + 60 * tm_T.tm_hour);}//==========================================================================// Returns the time of day rounded down to the nearest second as a fraction// of 1 day, i.e. compatible with Excel time formatting.//// Wraps the function long current_system_time(void) providing a trigger// for Excel calling and using the standard calling convention for Win32 DLLs.//==========================================================================double __stdcall Get_System_Time_C(long trigger){ return current_system_time() / (double)SECS_PER_DAY;}//==========================================================================// Returns the time of day to the nearest 100th of a second as a fraction// of 1 day, i.e. compatible with Excel time formatting.// // Takes one argument which is ignored but provides a means of triggering a// call to this function by Excel.//// On first call sets up the initial time using standard library routines// prototyped in <time.h> which provide system time rounded down to the// nearset second. Improves and maintains time to the nearest 100th of a// second using the C run-time clock() function that provides a meassure// to a supposed accuracy of CLOCKS_PER_SEC (1000) but is only reliable when// rounded to the nearest 100th of a second.//==========================================================================double __stdcall Get_Time_C(long trigger){ static bool first_call = true; static long initial_100ths; static double initial_time; if(first_call) { first_call = false; // do this part only once long T, T_last = current_system_time(); // Loop until the second changes, so no fractional second for(;(T = current_system_time()) == T_last ; initial_100ths = (clock() + 5) / CLOCKS_PER_100TH_SEC; // round to the nearest 100th second return initial_time = (T / (double)SECS_PER_DAY); // return the time } return initial_time + ((clock() + 5) / CLOCKS_PER_100TH_SEC - initial_100ths) / (SECS_PER_DAY * 100.0);}//==========================================================================// Wraps the C run-time function long clock(void) providing a trigger// for Excel calling and using the standard calling convention for Win32 DLLs.//==========================================================================long __stdcall Get_Clock(long trigger){ return clock();}---------------------------------------------------------------------------------------------------------------------------------------------------Below is what's in my .Def file so that functions get exported properly:EXPORTSGet_System_Time_CGet_Time_C
Last edited by tbonds on July 9th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
DominicConnor
Posts: 11684
Joined: July 14th, 2002, 3:00 am

Trouble with Steve Dalton's Excel/C++ Book Example

July 10th, 2005, 6:30 am

Attach the code, I'll have a look. My Dalton CD seems to have been "borrowed".
 
User avatar
tbonds
Topic Author
Posts: 246
Joined: July 14th, 2002, 3:00 am

Trouble with Steve Dalton's Excel/C++ Book Example

July 10th, 2005, 12:15 pm

Hi DCFC,I've updated my post to display the code for the .cpp and .def files.Thanks.
 
User avatar
Athletico
Posts: 872
Joined: January 7th, 2002, 4:17 pm

Trouble with Steve Dalton's Excel/C++ Book Example

July 10th, 2005, 1:40 pm

tbonds,Apparently by design, current_system_time() returns the number of seconds elapsed since midnight, so this linereturn current_system_time() / (double)SECS_PER_DAY;happens to be the fractional part of system time in the DATE (variant) representation.If you want Get_System_Time_C to return system time as a DATE, try this:double __stdcall Get_System_Time_C(long trigger){ SYSTEMTIME sysTime; ::GetLocalTime(&sysTime); // convert to variant date DATE timestamp; SystemTimeToVariantTime(&sysTime, & timestamp); return timestamp;}
Last edited by Athletico on July 9th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
tbonds
Topic Author
Posts: 246
Joined: July 14th, 2002, 3:00 am

Trouble with Steve Dalton's Excel/C++ Book Example

July 10th, 2005, 1:53 pm

Yes, you're right, I see that now.Thanks for checking this.
Last edited by tbonds on July 9th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
MattF
Posts: 925
Joined: March 14th, 2003, 7:15 pm

Trouble with Steve Dalton's Excel/C++ Book Example

July 11th, 2005, 8:23 am

If you're working through the book you should check out this list of known bugs which Steve Dalton himself posted: Dalton bugsI was a bit irritated at wasting several hours tracking down one of these myself and perhaps it overly influenced my review. It's a pretty good book because it contains a lot of information that you simply wont find elsewhere.
 
User avatar
tbonds
Topic Author
Posts: 246
Joined: July 14th, 2002, 3:00 am

Trouble with Steve Dalton's Excel/C++ Book Example

July 11th, 2005, 9:09 am

Thanks.Yes, I agree.No other book on the market regarding this subject so I'm being unusually patient with the bugs/mistakes as I find them.
Last edited by tbonds on July 10th, 2005, 10:00 pm, edited 1 time in total.
 
User avatar
SteveDalton
Posts: 10
Joined: December 22nd, 2004, 10:29 am

Trouble with Steve Dalton's Excel/C++ Book Example

August 5th, 2005, 1:06 pm

Once again, apologies to anyone who had to find out the hard way that I'm fallible.I recently corresponded with someone who said that they had found some functions in the example code that had the initial letters capitalised in a way that is not reflected in the book text (or the DEF file perhaps, from reading this). Some errors were fixed in a 2nd printing (at my request but not by me), so I'm looking into whether or not some new errors were inadvertantly introduced.If you have any questions/comments please feel free to send me a mail at steve@eigensys.com and I'll try and get back to you as soon as I can. Also, I have been asked by Wiley to work on a 2nd edition, so would welcome feedback.RegardsSteve Dalton
 
User avatar
tbonds
Topic Author
Posts: 246
Joined: July 14th, 2002, 3:00 am

Trouble with Steve Dalton's Excel/C++ Book Example

August 16th, 2005, 9:33 pm

Hi,Trying to use the Dalton book to create an XLL, but am unsure about how to proceed.I only want to create a simple XLL example so that I can better understand how the whole process works.I have a DLL which I now want to create as an XLL for Excel, fully registered and all that jazz.Can someone cite the pages in the Dalton book (or on the web if something better exists) which will allow me to create an XLL based on the Get Time DLL example used in Dalton's book?At the moment I don't know if all i have to do is add some lines to my .DEF file, or if I have to do some C++ coding for xloper, as I see examples of both in his book, but there is really no "recipe" given (that I can see) for exactly what needs to be done to create an XLL.Many Thanks.PS - Steve, I pm'd you, but not sure if you regularly check for messages. Regards.
 
User avatar
SteveDalton
Posts: 10
Joined: December 22nd, 2004, 10:29 am

Trouble with Steve Dalton's Excel/C++ Book Example

August 18th, 2005, 9:16 am

Hi tbonds - replied to your PM - regards Steve
 
User avatar
arthetalish1
Posts: 2
Joined: December 13th, 2006, 4:53 pm

Trouble with Steve Dalton's Excel/C++ Book Example

April 10th, 2008, 2:12 pm

I've just started working throught the book (and find it helpful). The example get_system_time_C works fine. Though when I try to modfy the code, I'm having problems getting Excel 2007 to load my .dll?I've used the exact methods as as in chapter 4, except I'm using some code from my old MSc course Example code for linking C++ to Excel , which should do the same thing. Unfortunately, I get the following debuggin output,'EXCEL.EXE': Loaded 'C:\Users\Ajay\C++_Projects\Davis_Excel_to_C++\Ajay_testdll\Ajay_testdll\Debug\Ajay_testdll.dll', Symbols loaded.'EXCEL.EXE': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll''EXCEL.EXE': Unloaded 'C:\Users\Ajay\C++_Projects\Davis_Excel_to_C++\Ajay_testdll\Ajay_testdll\Debug\Ajay_testdll.dll''EXCEL.EXE': Unloaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll'This occurs everytime I try to use the exported function in my spreadsheet? Many thanks in advance for your help
 
User avatar
arthetalish1
Posts: 2
Joined: December 13th, 2006, 4:53 pm

Trouble with Steve Dalton's Excel/C++ Book Example

April 10th, 2008, 11:55 pm

QuoteI've just started working throught the book (and find it helpful). The example get_system_time_C works fine. Though when I try to modfy the code, I'm having problems getting Excel 2007 to load my .dll?After nearly a day of this tedium, decided XLW is the simplest way to go. It's a nice book for full-time developer's, but if you're in a hurry what the point of "reinventing the wheel"?
 
User avatar
mj
Posts: 3449
Joined: December 20th, 2001, 12:32 pm

Trouble with Steve Dalton's Excel/C++ Book Example

April 15th, 2008, 4:25 am

As an author of xlw, I wonder how much total time I have saved people. NB version 3.0 will be out soon.
 
User avatar
Cuchulainn
Posts: 62898
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Trouble with Steve Dalton's Excel/C++ Book Example

April 15th, 2008, 10:56 am

QuoteOriginally posted by: mjAs an author of xlw, I wonder how much total time I have saved people. I think people should be very grateful to you. How many people have lost days just installing libraries? (to be honest, C++ newbies try this as well, which is like getting the keys of the auto without having had driving lesson).How many posts contain the word "install"??
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl
 
User avatar
unkpath
Posts: 289
Joined: January 13th, 2004, 8:44 pm

Trouble with Steve Dalton's Excel/C++ Book Example

April 16th, 2008, 1:36 am

QuoteOriginally posted by: arthetalish1QuoteI've just started working throught the book (and find it helpful). The example get_system_time_C works fine. Though when I try to modfy the code, I'm having problems getting Excel 2007 to load my .dll?After nearly a day of this tedium, decided XLW is the simplest way to go. It's a nice book for full-time developer's, but if you're in a hurry what the point of "reinventing the wheel"?errhm, let me try. maybe because xlw is a piece of s**t? maybe because if mj realized how limited xlw is, mj would also realize how much of people's time he is wasting and mj would stop beating his drum about it? maybe...
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On